Reputation: 27
Is it right to use session variables in a SQL query?
I have a query:
$sql="SELECT teacher.f_name,attendance.student_id,attendance.SNO ,attendance.s_section,attendance.DateTime FROM teach,subject,teacher,attendance WHERE teach.teacher_id= $_SESSION['username'] AND $_SESSION['username'] = teacher.teacher_id AND teach.SNO = subject.SNO";
I used session here from the previous page which the user sign in then save the username variable to a session and redirect tho this page where the query here
The output tells me "syntax error" in WHERE
statement line.
Upvotes: 0
Views: 99
Reputation: 126
Change AND $_SESSION['username'] = teacher.teacher_id
to AND teacher.teacher_id = $_SESSION['username']
Then change all $_SESSION['username']
to {$_SESSION['username']}
Upvotes: 1