Error with mysql SELECT FROM?
I've wrote a select from statement for my gaming system but it keeps returning no rows.
Could somebody spot my error?
This is my code. It's meant to redirect if the field returns differnet to one results, but I have one in the database with the service_id of 1 and user_id of 2.
$service_sql=mysql_query("SELECT * FROM user_services WHERE service_id='1' AND 'user_id'='2'");
if(开发者_运维技巧mysql_num_rows($service_sql)!=='1'){
echo mysql_num_rows($service_sql);
echo "error";
Remove the quotes from 'user_id' = '2'
You're comparing the values AND types of your variables with "!==", try either "!=" or remove the quotes from '1' :
mysql_num_rows($service_sql) != 1
Since mysql_num_rows
returns an integer, you'll always get false when strictly comparing it to a string.
$service_sql=mysql_query("SELECT * FROM user_services WHERE service_id='1' AND user_id='2'")
My instant reaction is that this needs changing
$service_sql=mysql_query("SELECT * FROM user_services WHERE service_id='1' AND 'user_id'='2'");
to
$service_sql=mysql_query("SELECT * FROM user_services WHERE service_id='1' AND user_id='2'");
Also, is user_id a number type or a char type ? if it's a number then change '1' to 1.
精彩评论