Jump to content

Why is this query failing?


ghurty

Recommended Posts

Why is this not working?

$query = "SELECT *  FROM `users` WHERE `userid` = " . $USERID AND `pin` = " . $PIN;

$result = mysql_query($query)

    or die("Web site query failed");

 

When I all I have is:

$query = "SELECT *  FROM `users` WHERE `userid` = " . $USERID;

$result = mysql_query($query)

    or die("Web site query failed");

 

It does work. But when I ad the PIN, it just fails. I have the variable $PIN assigned and I have a field called pin.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/179011-why-is-this-query-failing/
Share on other sites

you are concatenating incorrectly. you should use an editor with syntax highlighting, because the error will become very apparent.

$query = "SELECT *  FROM `users` WHERE `userid` = " . $USERID AND `pin` = " . $PIN;//bad query


$query = "SELECT *  FROM `users` WHERE `userid` = " . $USERID . " AND `pin` = " . $PIN; //fixed

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.