Jump to content

Variable trouble with mysql and php


debz89uk

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.