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
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...

Link to comment
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...

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.