It's 12:30am and I have been coding for 9 hours straight. I really need to get this project done, but MySQL is messing with my deadline. Could you examine this snippet for me and see if you can find out what is wrong?
PHP/MySQL Query
$q = $this->db->query("SELECT * FROM bans WHERE ip='".$ip."'");
Keeps returning the following error...
MYSQL Error [Oct 6th, 2010 11:31pm CDT]
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 '* FROM bans WHERE ip='206.53.90.231'' at line 1 (1064)
I do not see anything wrong with the query. I've even tried different methods of including the variable $ip but with no avail.
EDIT:
Just to add in here, the ip column in my database is a varchar(255).
EDIT 2:
Here is the whole affected code. Keep in mind that this is all in a class. If I'm missing something, let me know.
Line from another Function
if($this->isBanned($_SERVER['REMOTE_ADDR'])===true) { return json_encode(array('error'=>'You are banned from this ShoutBox.')); }
Affected Function
function isBanned($ip) {
$q = $this->db->query("SELECT * FROM bans WHERE ip='".$ip."'"); $num = $this->db->affected_rows;
if($num>0) { $row = $this->db->fetch_array($q); if(($row['expires'] < time()) && ($row['expires'] !== 0)) { $this->unbanUser($ip,'internal'); return false; } return true; } return false;
}
unbanUser function
function unbanUser($ip,$t='box') {
$q = $this->db->query("SELECT * FROM bans WHERE ip='".$ip."'"); $num = $this->db->affected_rows; if($num>0) { $q = $this->db->query("DELETE * FROM bans WHERE ip='".$ip."'");
return (($t=='box') ? json_encode(array('status'=>'removed')) : true); } else { return (($t=='box') ? json_encode(array('error'=>'Unable to locate the user.')) : true); }
}
To check syntax code: First, Drag and drop your SQL file or copy / paste your request directly into the editor above. Finally, you must click on "Check SQL syntax" button to display if there is an syntax error in your code.
The SHOW COUNT(*) ERRORS statement displays the number of errors. You can also retrieve this number from the error_count variable: SHOW COUNT(*) ERRORS; SELECT @@error_count; SHOW ERRORS and error_count apply only to errors, not warnings or notes.
I think it may be It is your DELETE
statement which is causing the error.
Remove the *
after the DELETE
and it should be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With