2013-02-28 71 views
0

如何在查詢中使用implode將值插入到db中。這裏是我的例子:在插入查詢中使用implode

HTML表單:

<form action="insert.php" method="post"> 
name:<input type="text" name="name" /><br /> 
address:<input type="text" name="address" /><br /> 
phone:<input type="text" name="phone" /><br /> 

<input type="submit" name="insert" value="insert" /> 
</form> 

我用這個代碼從申請表獲得彥博值:

$x = array_values($_POST); 

,並在這裏把「」琴絃之間的逗號這樣我就可以在查詢中使用它:

$x = "'".implode("','",$x)."'"; 

這裏是我做過什麼:

mysql_query("INSERT INTO dbtable (name, address, phone) 
         VALUES 
         ($x)"); 

當我回聲$ X: 的結果是: '姓名', '地址', '電話', '插入'

代碼打印 「插入」 < - 這是提交按鈕。我認爲這是問題

誰能幫助我解決我的錯誤,請 感謝

+0

你得到一個錯誤?你有沒有檢查你的錯誤日誌?你採取了哪些步驟來解決這個問題? – 2013-02-28 02:36:22

+0

沒有錯誤,但沒有插入:)謝謝 – user1358069 2013-02-28 02:37:33

+0

如果你迴應查詢並在PHPMyAdmin中運行它,它會運行嗎? – Achrome 2013-02-28 02:40:32

回答

0

的破滅shuld如:

$x =implode("','",$x)."'";