2013-03-07 74 views
0

我想不通,爲什麼我的INSERT INTO查詢是不工作...這裏是我的代碼:當這個代碼是拼命地跑PHP:MySQL的插入不工作

<?php 
session_start(); 
try 
{ 
$bdd = new PDO('mysql:host=localhost;dbname=gestion', 'root', ''); 
} 
catch(Exception $e) 
{ 
die('Erreur : '.$e->getMessage()); 
} 

$req = $bdd->prepare('INSERT INTO tasks (title, details, maturity, from, to) VALUES(:title, :details, :maturity, :from, :to)'); 
$req->execute(array(
        ':title'=>$_POST['title'], 
        ':details'=>$_POST['details'], 
        ':maturity'=>$_POST['maturity'], 
        ':from'=>$_SESSION['login'], 
        ':to'=>$_POST['to'] 
        )); 

header('Location: tasks.php'); 
?> 

什麼也沒有發生。

謝謝你的幫助。

答:

FROMTO都是保留字......所以,我不能使用它們這種方式。

+6

'FROM'和'TO'都是[MysQL保留關鍵字](http://dev.mysql.com/doc/refman/5.0/en /reserved-words.html)。你需要用反引號引用它們作爲列名。 – 2013-03-07 17:18:32

+0

你能捕獲sql錯誤嗎? – Bigood 2013-03-07 17:18:53

+1

刪除'header()'並檢查錯誤消息。 – take 2013-03-07 17:18:58

回答

0

from和to是mysql中的保留關鍵字。

你可以在MySQL「到」用「從」和....但你必須與這種性格來包裝他們:'(在鍵盤的左上方1個鍵)

所以寫`from`而不是`from`和`to`而不是