Jump to content

Recommended Posts

I've written out the following, but it returns a syntax error near the bolded portion. I don't see anything wrong with the syntax, but I'm sure theres something I missed. The script is supposed to scan the table to see if you have attacked your current target player 3 times in the last hour.

 

 

$q = mysql_query("SELECT COUNT(*) AS count FROM attack WHERE attacker_id = $AttackerId AND

defender_id = $AttackedID AND

attacktime BETWEEN DATE_SUB(NOW(), INTERVAL 1 HOUR) AND NOW()") or die(mysql_error());

$row = mysql_fetch_array($q) or die(mysql_error());

 

if($row['count'] == 3){

die("You have already attacked this person 3 times this hour.");

Link to comment
https://forums.phpfreaks.com/topic/208775-help-with-sql-error/
Share on other sites

Without the ability to echo the query, you can't really debug it. Separate the query from the query execution, and echo it along with mysql_error().

 

$q = "SELECT COUNT(*) AS count FROM attack WHERE attacker_id = $AttackerId AND defender_id = $AttackedID AND attacktime BETWEEN DATE_SUB(NOW(), INTERVAL 1 HOUR) AND NOW()"
mysql_query($q) or die('<br />Query string: ' . $q . '<br />Produced error: ' . mysql_error() . '<br />');

Link to comment
https://forums.phpfreaks.com/topic/208775-help-with-sql-error/#findComment-1090667
Share on other sites

Thanks. That pointed out my error and now the select command isn't giving an error. However, now its telling me mysql_fetch_array(): supplied argument is not a valid MySQL result resource. Any ideas?

 

 

$q = "SELECT COUNT(*) AS count FROM attack WHERE attacker_id = $AttackerId AND defender_id = $AttackedId AND attacktime BETWEEN DATE_SUB(NOW(), INTERVAL 1 HOUR) AND NOW()";
mysql_query($q) or die('<br />Query string: ' . $q . '<br />Produced error: ' . mysql_error() . '<br />');
$row = mysql_fetch_array($q) or die(mysql_error());

if($row['count'] == 3){
    die("You have already attacked this person 3 times this hour.");
} 

Link to comment
https://forums.phpfreaks.com/topic/208775-help-with-sql-error/#findComment-1090672
Share on other sites

$result = mysql_query($q) or die('<br />Query string: ' . $q . '<br />Produced error: ' . mysql_error() . '<br />');
$row = mysql_fetch_array($result) or die(mysql_error());

if($row['count'] == 3){
    die("You have already attacked this person 3 times this hour.");
} 

Link to comment
https://forums.phpfreaks.com/topic/208775-help-with-sql-error/#findComment-1090677
Share on other sites

Changed the structure to supply mysql_fetch_assoc() with a valid result . . .

$q = "SELECT COUNT(*) AS count FROM attack WHERE attacker_id = $AttackerId AND defender_id = $AttackedId AND attacktime BETWEEN DATE_SUB(NOW(), INTERVAL 1 HOUR) AND NOW()";

$result = mysql_query($q) or die('<br />Query string: ' . $q . '<br />Produced error: ' . mysql_error() . '<br />');

$row = mysql_fetch_assoc($result) or die(mysql_error());

if($row['count'] == 3){
    die("You have already attacked this person 3 times this hour.");
}

Link to comment
https://forums.phpfreaks.com/topic/208775-help-with-sql-error/#findComment-1090679
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.