0
我想插入到我的數據庫中,唯一的問題是我可以找到的是SQL不正確。我試圖尋找錯誤,但他們對於它們是什麼感到困惑。PDO插入未知的sql錯誤
$pdo = new PDO("mysql:host=$dbhost;dbname=$dbvideos;", $dbusername, $dbpassword);
$sql = "INSERT INTO Video ('Channel ID', 'Name', 'VideoDescription', 'VideoLocation') VALUES (:chanID, :vidName, :vDesc, :vLoc)";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(":chanID"=>$_POST['selectedChannel'], ":vidName"=>$_POST['videoName'], ":vDesc"=>$_POST['viddesc'], ":vLoc"=> $VideoLocation));
print_r($stmt->errorInfo());
有了錯誤輸出:
Array ([0] => 42000 [1] => 1064 [2] => 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 'ID, Name, VideoDescription,VideoLocation) VALUES ('1', 'Testing Video', 'This is' at line 1)
我預先檢查變量(類型匹配的數據庫,它們的存在與前一頁的驗證)。連接工作正常。所以SQL是我能找到的唯一錯誤。
將後面的勾號(')不加引號(')括起來?另外,在列名中有空格並不是一個好主意。改用下劃線? –