Jump to content

syntax assistance required.


blue-genie

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/203055-syntax-assistance-required/
Share on other sites

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

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.

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)

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?

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.