PHP MySQL 插入表单发布问题


php mysql insert form post issue

当我手动插入时,我的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>

没有错误,仅检查空白表单字段。帖子和功能之间似乎存在问题,但我无法确定问题。

add_post() $post 中已准备好,但在最终调用mysql_query中没有使用。

您准备要在 INSERT INTO user_blog SET 语句中使用的$post,但您正在使用INSERT INTO user_blog () VALUES()进行最终调用。

在值中,仅插入 '$blog_author,其余为字符串文字。

文本区域中没有 name 属性,因此它不会获取内容