1

I'm a new grue with php, When I write this code:

$query2="SELECT `User_id` FROM `users` WHERE `E-mail`=$email";
$sql2= mysql_query($query2);
if(mysql_num_rows( $sql2)>0){
   $Name2=mysql_fetch_array($sql2); 
   $customer_id=$Name2[0];
   echo $customer_id."ccccccccccc";
}
else{
     $errormessage2="<font color='red'>Invalid Email,Try 
     again</font>"."Error description: ";
}
if($sql2 === FALSE) { 
   cho "erro";
   echo mysql_error();
   die(mysql_error());
}

I'm getting this error:

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 '@yahoo.com' at line 1

Can anyone help?

Ahmed Sayed
  • 31
  • 1
  • 4

4 Answers4

1

try this query

$query2="SELECT `User_id` FROM `users` WHERE `E-mail`='".$email."';
Amit Visodiya
  • 856
  • 6
  • 18
1

Your SQL is wrong, try this -

$query2="SELECT User_id FROM users WHERE E-mail='$email'";

atefth
  • 1,624
  • 13
  • 26
1

Please do everyone, and especially yourself a favor and read through Preventing SQL-injection in PHP

It will help you write proper queries, preventing someone from using "; DELETE FROM users; as an email-address, thereby deleting all your data. It will also fix this error you're currently seeing

Community
  • 1
  • 1
Sjon
  • 4,989
  • 6
  • 28
  • 46
0

just change in WHERE E-mail='".$email."'";

Mirza Obaid
  • 1,707
  • 3
  • 23
  • 35