CagedApe Posted July 24, 2010 Share Posted July 24, 2010 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."); Quote Link to comment https://forums.phpfreaks.com/topic/208775-help-with-sql-error/ Share on other sites More sharing options...
Pikachu2000 Posted July 24, 2010 Share Posted July 24, 2010 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 />'); Quote Link to comment https://forums.phpfreaks.com/topic/208775-help-with-sql-error/#findComment-1090667 Share on other sites More sharing options...
CagedApe Posted July 24, 2010 Author Share Posted July 24, 2010 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."); } Quote Link to comment https://forums.phpfreaks.com/topic/208775-help-with-sql-error/#findComment-1090672 Share on other sites More sharing options...
jcbones Posted July 24, 2010 Share Posted July 24, 2010 $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."); } Quote Link to comment https://forums.phpfreaks.com/topic/208775-help-with-sql-error/#findComment-1090677 Share on other sites More sharing options...
Pikachu2000 Posted July 24, 2010 Share Posted July 24, 2010 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."); } Quote Link to comment https://forums.phpfreaks.com/topic/208775-help-with-sql-error/#findComment-1090679 Share on other sites More sharing options...
CagedApe Posted July 24, 2010 Author Share Posted July 24, 2010 Thank you Pikachu! That works perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/208775-help-with-sql-error/#findComment-1090701 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.