I am using hidden fields to transfer variables from several pages to this one "email.php" page. The variable is called $class. And the page holds the following query : $sql = " select student_email.student_id, student_email.info_2, student_email.info_3, student_email.info_3, '$class' from student_email, AllClasses where student_email.student_id = AllClasses.student_id and $class = 1"; Code (markup): This query doesnt work, but it works if I leave the first '$class' (after student_email.info_3) and replace the second (at the very end of the query) with the actual column name. I don't understand why it would work in the first part but not the second (and I have tried putting it as '$class' = 1 with no such luck either).
You have wrong query $sql = "select student_email.student_id, student_email.info_2, student_email.info_3, student_email.info_3, `$class` from student_email, AllClasses where student_email.student_id = AllClasses.student_id and $class = 1"; PHP: Better sprintf("select student_email.student_id, student_email.info_2, student_email.info_3, student_email.info_3, %s from student_email, AllClasses where student_email.student_id = AllClasses.student_id and %s = 1",mysql_real_escape_string($class),mysql_real_escape_string($class)); PHP:
Thanks guys, I've tried all of your suggestions, unfortunately none of them are working :/ I changed the "error query database" to mysql error and it came back with this as the problem "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from student_email, AllClasses where student_email.student_id = AllClasses.stu' at line 1" so PF is getting changed to stu?
Okay, fixed. The problem was that because the form and the php were all in the one document, and because I was using hidden fields for variables (coming from the previous page) I had to declare the variable again in the second form.