|
Where is the $MyLangVar declared? if it is inside the if statement it could be lost after the if statement is completed.
|
|
|
|
|
Hello Nick,
QUESTION PART:
This is something I've not understood properly:
if there is not a define, dim, type specification at the moment of declaring a variable, how one know where it has been declared?
Moreover if a web is not a structured setting of pages (I mean that one can access any page of the web without any specific order thanks to the search engines).
At the beginning of each file of the site I've got something like:
<?php
include($_SERVER['DOCUMENT_ROOT'].'/file_that_must_be_included.php');
$MyLangVar = $GLOBALS['MyLangVar'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<h
<html>
<head>
Then, inside the "file_that_must_be_included.php" I've done this:
<?php
include($_SERVER['DOCUMENT_ROOT'].'/another_global_file.php');
if (!isset($MyLangVar))
{
$MyLangVar = "English";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
Here it is where I'm trying to check if the variable has been initialized or not, and if it has not been initialized then I'm setting it to the default language.
CONCLUSIONS / IDEAS:
After writing the previous lines, I've thought:
* If declaring a variable inside a "if" clause makes it local, then having that "if (!isset..." it has no sense until the gloabal variable has been declared because just after leaving the if clause the var will be "destroyed".
* I guess I should change the line order in the main files: putting the "$MyLangVar = $GLOBALS['MyLangVar'];" line at the beginning, just before the "include($_SERVER['DOCUMENT_ROOT'].'/file_that_must_be_included.php');". In that way I've declared the $MyLangVar, it will become global for all the file (I guess, please confirm that) and therefore I'll only initialize it once (inside the sub_file "/file_that_must_be_included.php".
* I've tried that but in the 404.php file I can see a message telling me: Undefined index MyLangVar'...
Lost again...
Can you do something with all this data?
Thank you in advance!
|
|
|
|
|
If the variable is already declared it will stay global. Undefined index means that element of the array globals is not set.
The most useful function in php is var_dump()! It usually tells you what you need to know. I would var_dump( $GLOBALS ) and see what you get. feel free to contact me directly if you are still having dramas.
|
|
|
|
|
come to think of it $GLOBALS will not be storing the values once the pages when another page is loaded. What you want is
<?php session_start();
$_SESSION['MyLangVar'] = ??;
Then the variable will be stored between page loads.
|
|
|
|
|
You are my idol for today!
Thank you very much for your help!
$_SESSION has made it!
|
|
|
|
|
Joan, I'm curious, which PHP framework do you use?
modified 1-Aug-19 21:02pm.
|
|
|
|
|
Now I'm using EasyPHP 5.3.5.0.
|
|
|
|
|
So I'm writing an index page that calls a header file within a different folder. The pages that seem to not work are the index pages WITHIN other folders and using ../ to get back to the root folder and back into the include folder, if the pages are within the root folder and call the header by going through the include folder, it works.
Kind of hard to explain..
But I'm getting these errors..
Warning: main(paul_menubar_test/menubar_test_filesavail.php) [function.main]: failed to open stream: No such file or directory in /home/new2/include/headers.php on line 190
Warning: main() [function.include]: Failed opening 'paul_menubar_test/menubar_test_filesavail.php' for inclusion (include_path='.:/usr/php4/lib/php') in /home/new2/include/headers.php on line 190
And that's an index file that's within a different folder in the root folder.
I have an index file in the root folder that does the call for the include/header and it works.
If you need any clarification, please ask.. I don't know how else to word it.
I've checked google and people just say "lol check ur pointers," I did, like a 100 times. I've tried all sorts of "/," "../" and all that. I've also read that I may need to change the permissions of the folder or something? I'm not sure how to do that.. but the other problem is every single page calls the FOOTER file, which is also in the "include folder," has no problem.
-Paul
|
|
|
|
|
lol, check your pointers!
just kidding
can you give an example of the file structure and explain how pages are called from one to the next? I have an idea you may have an issue related to your includes as it pertains to the current local directory and the use of relative paths.
Chris J
www.redash.org
|
|
|
|
|
if you include other files, the relative path back to root is from the first file.
so if page A is /A/index.php, which does a require_once('B/header.php') (in other words requires /A/B/header.php), then if /A/B/header.php wants to require_once /C/D/miniheader.php it needs to
require_once('../C/D/miniheader.php');
i.e. only one folder up (all the requires are relative to /A/index.php, the first script that ran)
|
|
|
|
|
if it is in the root of the site try
"{$_SERVER['DOCUMENT_ROOT]}/paul_menubar_test/menubar_test_filesavail.php";
|
|
|
|
|
hello
my work internet computer has been blocked by fortiguard web filter and i can't access half of the websites
i don't have admin user and i cant download any progrem including programming compailers
can someone help me please?
thanks in advenced
|
|
|
|
|
Do or do not, there is no "try"
|
|
|
|
|
|
|
How can I send variable to another form without include ?
|
|
|
|
|
Depends...is this second form on the same page or a different page?
Chris J
www.redash.org
|
|
|
|
|
|
|
 $_POST and $_GET just for input type but my variable isn't that.this is my code I want when user click on button insert data to database but I can't access to variable
$row[lsname],$row[teachername],...even this page and other page?another my question is why variable like$_POST[t] isn't recognaize in function?!!!even I write global
$_POST[t] but it's error
<?php
session_start();
echo ($_SESSION[users]);
echo "$_POST[t]";
?>
<html>
<form method="post" action="reqire.php">
<?php
require_once ('db.php');
$db = new db("root","","regstudent","localhost");
function aa()
{
require_once ('db.php');
$db = new db("root","","regstudent","localhost");
$db->query("INSERT INTO register(`user`, `lsname`, `teachername`, `classday`, `starttime`, `endtime`, `examtime`)VALUES('$_SESSION[user]','$row[lsname]','$row[teachername]','$row[classday]','$row[starttime]','$row[endtime]','$row[examtime]') ");
echo "one record added";
}
echo "<table border='4' bordercolor='CC0099' width=100% height=20% >";
echo "<tr><th>Name</th><th>Professor</th><th>Capacity</th><th>Exam</th><th colspan='3'>classtime</th></tr>";
$result = mysql_query("SELECT * FROM class");
while($row = mysql_fetch_assoc($result))
{
if($_POST[t]==$row[lsname])
{
foreach($row as $key=>$var2)
{
echo "<td align='center'>$var2 </td>";
}
echo "<td align='center'><input type='submit' value='Register' onclick='aa()'></td> ";
}
echo "</tr>";
}
echo"</table>";
?>
</form>
</html>
please help me I mystify in my project :(
|
|
|
|
|
if you mean what I think you mean:
first page:
<?php
$sSomething='378923';
echo '<input type="hidden" name="something" value="'.htmlentities($sSomething).'">';
?>
second page:
<?php
$sSomething=(isset($_POST['something']) ? $_POST['something'] : '');
?>
|
|
|
|
|
When I must debug post, get or session variables I use this at the top of the target page.
<?php
session_start();
echo "<pre>";
print_r($_POST);
print_r($_SESSION);
echo "</pre>";
?>
This will allow you to see what is being passed to your target page so you will know if the data is making it or not.
I see that you defined your function aa()...but where is it called from?
Chris J
www.redash.org
|
|
|
|
|
I called it when I define submit button onclick attributes
echo "<td align='center'><input type='submit' value='Register' onclick='aa()'></td> ";
|
|
|
|
|
no you are calling a javascript function called aa() and that I'm guessing does not exist?
remeber php is executed on the server. The onclick is a javascript event that is triggered on the users browser. So you are most likely getting a undefined from the browser if the form submits to itself (i.e. - the scripts name is "reqire.php") But the error I think is wiped as the page reloads.
The php function aa() is never called.
On a side note, its really bad to:
1) have a database connection based on root, to much access for what is needed.
2) display a password in a forum, big security hole.
Chris J
www.redash.org
|
|
|
|
|
The function aa() work but I can't access the variable my big problem is I don't know user click in which button to insert data I agree with you but I can't insert in javascript!I think I should solve this problem in another way what's your suggestion?
|
|
|
|