PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to pass variables across various pages and I believe sessions is the best way, but Im afraid I keep getting the following error on the page where my session starts:
First, never use the "short" PHP opening tag. In other words, always use <?php.
Second, you're missing the semicolon at the end of session_start(); That causes the next line to be read as part of the first line, which causes the parser to see the variable $getjob or $_SESSION where it's not expecting a variable, which is what the error message said.
I trust that on the other pages you are also calling session_start() at the top and referencing job with $_SESSION['job'] and not $_POST['job'].
In the example you posted you are getting into some trouble with the quotes. You missed a single quote out of the SQL query and you also tried to use single quotes inside single quotes. In other words, change this:
$query1 = "SELECT * FROM Job_Spec WHERE Project_Name ='" . $_POST['job'] . "'";
I would strongly recommend that you use mysql_real_escape_string() with every variable which you are passing from the user into a database, which would result in this:
There is really not enough information to begin to understand your problem. Perhaps if you showed the <form> statement with the action and method and the part of the form body where the value of 'job' is set it would help.
Also your first post looks as though it's the wrong way round. Do you really have multiple pages with forms setting the job variable, and a single page getting the value from the session variable?
Last edited by JeffG on Mon Mar 09, 2009 7:02 am, edited 1 time in total.
$query1 = "SELECT * FROM Job_Spec WHERE Project_Name ='$getjob'";
echo "$query1";//just to check the actual query being passed.
$result1 = mysql_query($query1)
or die ("Couldn't execute query mysql_error()"); //check whats the error before exiting
$query1 = "SELECT * FROM Job_Spec WHERE Project_Name ='$getjob'";
echo "$query1";//just to check the actual query being passed.
$result1 = mysql_query($query1)
or die ("Couldn't execute query mysql_error()"); //check whats the error before exiting
I tried that and it echos :
$query1 = "SELECT * FROM Job_Spec WHERE Project_Name =''
Then I try and runt the query and its back to the blank screen!
Somewhere lower down Page 1 you have a submit button and then close off the form.
Page 1 itself is 'go.php', otherwise the assignment to the session variable will only take place when Page 1 is first executed, and not when the form is submitted and the post actually has something in it.