首页 > 解决方案 > mysqli_query 不工作 INSERT INTO 不工作

问题描述

好的,所以这是非常基本的,但它让我发疯

<div class="heading"><h2>Make a post<h2></div>
            <form action="post.php" method="POST">
            <div class="head"><h3>Title</h3></div>
                <textarea name="title" rows="2" cols="45"></textarea>
            <div class="desc"><h3>Content</h3></div>
                <textarea name="description" rows="15" cols="45"></textarea><br>
            <input type="submit" value="Submit">
            <p id="error_p"><?php echo (!empty($_SESSION['post_message']))? $_SESSION['post_message']:""; ?></p>
            </form>

html部分

if(!empty($_POST['title']) && !empty($_POST['description']))
{


    $title=$_POST['title'];
    $description=$_POST['description'];
    $user_id=$_COOKIE['user_id'];


    $query="INSERT INTO posts (title,description,user_id)
    VALUES('".$title."','".$description."','".$user_id."');";
    $result=mysqli_query($conn,$query);
    if($result)
    {
        $_SESSION['post_message']="Posting succ";
        header('Location: profile.php');
    }
    else
    {
        $_SESSION['post_message']="something gone wrong";
        header('Location: profile.php');
    }

}

php部分

我只是找不到问题,无论我做什么,我都会遇到“出现问题”错误。

标签: phpmysql

解决方案


推荐阅读