ghurty Posted January 18, 2010 Share Posted January 18, 2010 Why is this query select not working. When I have this one, it is always writing a value of 1 to the tmp variable: $GROUP = $_SERVER["argv"][1]; $GROUP = trim($GROUP); $GROUP = ltrim($GROUP); $USERID = $_SERVER["argv"][2]; $USERID = trim($USERID); $USERID = ltrim($USERID); $link = mysql_connect("localhost", "root", "passw0rd") or die("Data base connection failed"); mysql_select_db("dialer") or die("data base open failed"); $query = "SELECT * FROM `list` WHERE ( userid = '$USERID' AND group = '$GROUP' )"; $result = mysql_query($query) or die("Web site query failed"); $reccount = mysql_num_rows($result) ; write("SET VARIABLE tmp $reccount"); However, if I set it like this, then it counts the amount of rows properly: $query = "SELECT * FROM `list` WHERE `group` = " . $GROUP; The problem is that I want a count of the amount of records that have the both, the group# as well as userid#. Looking at the debug, I see the values for $GROUP and $USERID are passed onto the script. Thank You Link to comment https://forums.phpfreaks.com/topic/188854-why-is-this-query-failing/ Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 'Group' in MySQL is a reserved word. $query = "SELECT * FROM `list` WHERE ( `userid` = '$USERID' AND `group` = '$GROUP' )"; Link to comment https://forums.phpfreaks.com/topic/188854-why-is-this-query-failing/#findComment-997053 Share on other sites More sharing options...
ghurty Posted January 18, 2010 Author Share Posted January 18, 2010 So why is the second version working? Thanks Link to comment https://forums.phpfreaks.com/topic/188854-why-is-this-query-failing/#findComment-997054 Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 Because you are enclosing the group field name.. `group` as opposed to just group Link to comment https://forums.phpfreaks.com/topic/188854-why-is-this-query-failing/#findComment-997057 Share on other sites More sharing options...
ghurty Posted January 18, 2010 Author Share Posted January 18, 2010 Oh I get it. Thank you. I worded it differently I it works now. $query = "SELECT * FROM `list` WHERE `userid` = " . $USERID . " AND `group` = " . $GROUP; Thanks Link to comment https://forums.phpfreaks.com/topic/188854-why-is-this-query-failing/#findComment-997059 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.