Sono le 12:30 e sto codificando per 9 ore di fila. Ho davvero bisogno di portare a termine questo progetto, ma MySQL sta mettendo a posto la mia scadenza. Potresti esaminare questo frammento per me e vedere se riesci a scoprire cosa c'è che non va?Cosa c'è di sbagliato in questa query MySQL?
PHP/MySQL Query
$q = $this->db->query("SELECT * FROM bans WHERE ip='".$ip."'");
continua a tornare il seguente errore ...
MYSQL errore [6 Ott 2010 23:31 CDT]
Hai un errore nella la tua sintassi SQL; controllare il manuale che corrisponde alla versione del server MySQL per la sintassi diritto di utilizzare vicino a '* FROM WHERE divieti ip =' 206.53.90.231 '' at line 1 (1064)
non vedo niente di sbagliato con il query. Ho anche provato diversi metodi per includere la variabile $ ip ma senza risultati.
EDIT:
solo aggiungere qui, la colonna diip nel mio database è un varchar (255).
MODIFICA 2:
Ecco l'intero codice interessato. Tieni presente che questo è tutto in una classe. Se mi manca qualcosa, fammi sapere.
linea da un'altra funzione
if($this->isBanned($_SERVER['REMOTE_ADDR'])===true) { return json_encode(array('error'=>'You are banned from this ShoutBox.')); }
interessato Funzione
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;
}
funzione unbanUser
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); }
}
Provare a stampare '$ ip' poco prima che la query – codaddict
Strano, anche se avete fatto fuggire con' mysql_real_escape_string() 'nella classe database che non dovrebbe pregiudicare la stringa IP vostro errore sta parlando ... – BoltClock
The la query sembra corretta, supponendo che non ci siano caratteri insoliti non stampabili. L'errore che sta vedendo è a '*. Presumo che la stringa sia tutta ASCII, non UTF-8? – cHao