那麼我應該怎麼做代碼?PHP如何循環我從html表單獲得的數據並將它們保存到mysql數據庫中?
比方說,我的形式是:
<form action="check.php" method="POST">
<textarea name="ans[0]"> </textarea>
<textarea name="ans[1]"> </textarea>
<textarea name="ans[2]"> </textarea>
<textarea name="ans[3]"> </textarea>
<input type="submit" />
的check.php:
<?php
include('mysql.php'); // in this file i get connected to my db
foreach($ans as $index)
{
//I want to make this to do that:
mysql_query("UPDATE mytable SET $ans = '$ans[1]' WHERE user = 'Me'"); // How do I make that to update $ans[0] for first loop scan, than in next loop scan $ans[1] then $ans[2] and so on...
}
?>
是的,我對這些東西洙初學者,而且不知道如何代碼應該工作。感謝您的回答。
使用$ _POST ['ans']來訪問您發佈的變量。但更重要的是,重寫SQL,因爲它使用了不推薦的mysql_ *函數,並且對SQL注入開放。 – Xatoo