debz89uk Posted March 29, 2010 Share Posted March 29, 2010 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"; 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). Link to comment https://forums.phpfreaks.com/topic/196835-variable-trouble-with-mysql-and-php/ Share on other sites More sharing options...
andrewgauger Posted March 29, 2010 Share Posted March 29, 2010 Doesn't the second $class refer to table Allclasses? So don't you mean: ... Where student_email.student_id=AllClasses.student_id and $class.AllClasses = 1"; Link to comment https://forums.phpfreaks.com/topic/196835-variable-trouble-with-mysql-and-php/#findComment-1033309 Share on other sites More sharing options...
debz89uk Posted March 29, 2010 Author Share Posted March 29, 2010 The correct code for the class is $sql = " select student_email.student_id, student_email.info_2, student_email.info_3, student_email.info_3, AllClasses.PF from student_email, AllClasses where student_email.student_id = AllClasses.student_id and AllClasses.PF = 1"; (for one instance) and the variable $class = AllClasses.PF Link to comment https://forums.phpfreaks.com/topic/196835-variable-trouble-with-mysql-and-php/#findComment-1033312 Share on other sites More sharing options...
andrewgauger Posted March 29, 2010 Share Posted March 29, 2010 First correction: "$class.AllClasses" should have been "AllClasses.$class" even though that isn't what you wanted. Honestly I don't see anything wrong with what you are doing. Just make sure the content of the variable is correctly formatted. Strip whitespace if necessary. Otherwise--sorry I see nothing wrong with your implementation Link to comment https://forums.phpfreaks.com/topic/196835-variable-trouble-with-mysql-and-php/#findComment-1033328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.