Home > Software design >  sql select not working with php variable as search for [duplicate]
sql select not working with php variable as search for [duplicate]

Time:09-28

I have looked at similar questions, but they do not have solutions to what I think is a very simple problem.

This does work...

    $query = "SELECT * FROM user WHERE email='b^^^^^^^^@^^^^^^^^^^.com'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);

BUT This does NOT work...

    $myemail='b^^^^^^^^@^^^^^^^^^^.com';
$query = "SELECT * FROM user WHERE email=$myemail";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);

When I do WHERE on the PHP variable I do not get a result. BUT if I type in the value to search for it finds it with no problem I have done this many times before and never had this problem.

CodePudding user response:

$myemail='b^^^^^^^^@^^^^^^^^^^.com';
$query = "SELECT * FROM user WHERE email='$myemail'"; // You missed (') in this line
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
  • Related