我的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