2017-05-14 70 views
0

screenshotINSERT INTO出錯PHP笨

$sql = "INSERT INTO `waitinglist` (`reserver`, `roomNumber`, `hotelNumber`, `queueDepth`) 
     VALUES(".$this->db->escape($reserver).", ".$room.", ".$i.", ".$queueDepth+1.")"; 
$this->db->query($sql); 

我做了什麼錯?

+0

_You意味着APPART from_你的腳本是[SQL注入攻擊]的風險(http://stackoverflow.com/questions/60174/how-can-i-prevent-sql -injection-in-php) 看看發生了什麼事[Little Bobby Tables](http://bobby-tables.com/)即使 [if你是逃避投入,它不安全!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) 使用[編寫的參數化語句](http ://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly

+0

是所有4列數字,還是其中的一些文本列 – RiggsFolly

回答

0

使用更好的編輯器/ IDE,錯誤高亮顯示,這是很容易解決語法錯誤:

$sql = "INSERT INTO `waitinglist` (`reserver`, `roomNumber`, `hotelNumber`, `queueDepth`) 
     VALUES(".$this->db->escape($reserver).", ".$room.", ".$i.", ".($queueDepth+1).")"; 
+0

或只是'「,」。 $ queueDepth + 1。 「)」;' – RiggsFolly

+0

@RiggsFolly - 這是拋出錯誤的部分。 – shaggy