我的mysql插入語句會在我手動插入時通過,但是表單不會發布。任何幫助表示讚賞。php mysql插入表單發佈問題
表單
<form method="post" action="">
<h4>Title</h4>
<input type="text" id="post_title" />
<h4>Location</h4>
<input type="text" id="post_location" />
<h4>My Tale</h4>
<textarea id="post_content" ></textarea>
<input type="submit" value="Share"/><br />
</form>
表單處理器
<pre>
if (isset($_GET['success']) === true) {
echo 'Your journal entry has been added';
} else {
if (empty($_POST) === false && empty($errors) === true) {
$post_data = array(
'post_title' => $_POST['post_title'],
'post_location' => $_POST['post_location'],
'post_content' => $_POST['post_content']
);
add_post($user_id, $post_data);
header('Location: settings.php?success');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
</pre>
,處理後處理
<pre>
function add_post($blog_author, $post_data) {
$post = array();
array_walk($post_data, 'array_sanitize');
foreach($post_data as $field=>$data) {
$post[] = '`' . $field . '` = \'' . $data . '\'';
}
mysql_query("INSERT INTO user_blog (`post_author`,`post_title`,`post_location`,`post_content`) VALUES ('$blog_author','post_title','post_location','post_content')");
}
</pre>
有沒有錯誤,只是檢查空白表單域的作用。帖子和功能之間似乎存在一個問題,但我不能確定這個問題。
**危險**:您正在使用[an **過時的**數據庫API](http://stackoverflow.com/q/12859942/19068)並應使用[現代替換](http:// php.net/manual/en/mysqlinfo.api.choosing.php)。你也**易受[SQL注入攻擊](http://bobby-tables.com/)**,現代的API會使[防禦]更容易(http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)自己從。 – Quentin