Few others have got this same problem at the outset, however, I'm repeating this question because mine seems to be specific to EMail IDs.
I have a query that retrieves the password given a specific email id as input. THis is my query
Select Password from userauth where user_name in (select id from users where email = 's.sriram@example.com')
This query executes without any problem when done from phpMyAdmin.
However, it doesn't work when I do it through a php script. That php script is as follows:
<?php
// Grab User submitted information
$email = $_POST["users_email"];
$pass = $_POST["users_pass"];
// Connect to the database
$con= mysql_connect("localhost","root","sriram123");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Select the database to use
mysql_select_db("mydb",$con);
echo "Select Password from userauth where user_name in (select id from users where email = '$email')";
$result = mysql_query("Select Password from userauth where user_name in (select id from users where email = $email)");
if($result === FALSE) {
echo "Error Occured. ";
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result))
{
echo $row['Password'];
}
mysqli_close($con);
?>
Now, I get an error message like this when I execute it:
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 '@example.com)' at line 1
I am new to PHP, and i'm just not sure why this thing works in phpMyAdmin but fails to work in my PHP script.