blue-genie Posted May 27, 2010 Share Posted May 27, 2010 here's my select statement SELECT COUNT(*) as count FROM gamestats WHERE statsPlayerID=1 AND statsGameID = 119 if i run this in the sql window of xampp returns 2 - which is correct then i try do this <?php session_start(); include 'config.php'; include 'opendb.php'; $playerid = $_REQUEST['pID']; $gameid = $_REQUEST['gID']; //"SELECT COUNT(*) as played FROM gamestats WHERE statsPlayerID = '".$player."' AND gamestats.statsGameID = '".$gameid."'")) { $result = mysql_query("SELECT COUNT(*) as count FROM gamestats WHERE statsPlayerID=".$playeridID." AND statsGameID = '".$gameid."'") or die ('Error: '.mysql_error ()); $row = mysql_fetch_array($result,MYSQL_ASSOC); echo $row[count]; ?> and the result is 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 'AND statsGameID = ''' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/203055-syntax-assistance-required/ Share on other sites More sharing options...
GenuineSounds Posted May 27, 2010 Share Posted May 27, 2010 Shouldn't you use _get instead of _request? Quote Link to comment https://forums.phpfreaks.com/topic/203055-syntax-assistance-required/#findComment-1063997 Share on other sites More sharing options...
blue-genie Posted May 27, 2010 Author Share Posted May 27, 2010 i've been using request all along. someone told me to use request (cant' remember why) just tried changing it to GET - same error Quote Link to comment https://forums.phpfreaks.com/topic/203055-syntax-assistance-required/#findComment-1064000 Share on other sites More sharing options...
GenuineSounds Posted May 27, 2010 Share Posted May 27, 2010 result = mysql_query("SELECT COUNT(*) as count FROM gamestats WHERE statsPlayerID=".$playeridID." AND statsGameID = '".$gameid."'") or die ('Error: '.mysql_error ()); into result = mysql_query("SELECT COUNT(*) as count FROM gamestats WHERE statsPlayerID=\".$playeridID.\" AND statsGameID = \".$gameid.\"") or die ('Error: '.mysql_error ()); I think that's right... Quote Link to comment https://forums.phpfreaks.com/topic/203055-syntax-assistance-required/#findComment-1064003 Share on other sites More sharing options...
mattal999 Posted May 27, 2010 Share Posted May 27, 2010 result = mysql_query("SELECT COUNT(*) as count FROM gamestats WHERE statsPlayerID=".$playeridID." AND statsGameID = '".$gameid."'") or die ('Error: '.mysql_error ()); into result = mysql_query("SELECT COUNT(*) as count FROM gamestats WHERE statsPlayerID=\".$playeridID.\" AND statsGameID = \".$gameid.\"") or die ('Error: '.mysql_error ()); I think that's right... That would just escape the quotes and cause WHERE statsPlayerID=".1." which isn't really what he wants You're using the wrong variable name by the way. Easy mistake to make. You use $playeridID in the query, which should be $playerid. Quote Link to comment https://forums.phpfreaks.com/topic/203055-syntax-assistance-required/#findComment-1064004 Share on other sites More sharing options...
blue-genie Posted May 27, 2010 Author Share Posted May 27, 2010 I managed to change it to now throw an error anymore $result = mysql_query("SELECT COUNT(*) as count FROM gamestats WHERE statsGameID = '".$gameid."' AND statsPlayerID = '".playerid."'") or die ('Error: '.mysql_error ()); what is odd though is that if I hard code my variables into this query it returns 2 but if i use my variables as above it returns 0. i am highly confused. (not a php developer - do flash but am trying to fix this) Quote Link to comment https://forums.phpfreaks.com/topic/203055-syntax-assistance-required/#findComment-1064006 Share on other sites More sharing options...
GenuineSounds Posted May 27, 2010 Share Posted May 27, 2010 LOL right when I was posting that you did all by yourself '".$playerid."' Quote Link to comment https://forums.phpfreaks.com/topic/203055-syntax-assistance-required/#findComment-1064007 Share on other sites More sharing options...
blue-genie Posted May 27, 2010 Author Share Posted May 27, 2010 i found the problem (bar the typos) but I don't understand why. when i hard coded the values as strings it worked but when i ran it through the browser with querystring or via flash it didn't work because I was casting the values in flash as Numbers - in the database they were varchars. changed them to strings in flash and bobs my uncle it works - strange! any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/203055-syntax-assistance-required/#findComment-1064013 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.