douzizang7783 2016-01-24 08:44
浏览 16
已采纳

我的代码在这里有什么问题吗? [重复]

This question already has an answer here:

whenever I want to insert data with my form ,everything woks fine except the content field that does not insert anything to db!

Here's my full code:

    <?php 
if (isset($_POST['submit'])){
    $post_title = $_POST['title'];
    $post_date = date('d-m-y');
    $post_author = $_POST['author'];
    $post_keywords = $_POST['keywords'];
    $post_content = $_POST['content'];
    $post_image = $_FILES['image']['name'];
    $image_tmp = $_FILES['image']['tmp_name'];
    $post_summary = $_POST['summary'];

    if ($post_title=='' || $post_keywords=='' || $post_content='' || $post_author=='' || $post_summary==''){
        echo '<script>alert("Some fields are missing")</script>';
    }else{
        move_uploaded_file($image_tmp,"post_images/$post_image");
        $insert_query = "INSERT INTO posts 
    (post_title, post_date, post_author, post_image, post_keywords, post_content, post_summary)
    VALUES ('$post_title', '$post_date', '$post_author', '$post_image', '$post_keywords', '$post_content' , '$post_summary')";
        $insert_post = mysqli_query($con,$insert_query);
        if ($insert_post){
            echo '<h3 style="color:green">Post has been added successfully.</h3>';
        }elseif (!$insert_post){
            echo mysqli_error($con);
        }else{
            echo "Somthing goes wrong! Please contact with our support team...";
        }
    }
}
?>
<form method="POST" action="" enctype="multipart/form-data">
    <table width="600" align="center" border="10">
        <tr>
            <td align="center"><h6>Insert Post Title</h6></td>
            <td align="center"><input type="text" name="title"/></td></br>
        </tr>
        <tr>
            <td align="center"><h6>Insert Post Author</h6></td>
            <td align="center"><input type="text" name="author"/></td></br>
        </tr>
        <tr>
            <td align="center"><h6>Insert Post Keywords</h6></td>
            <td align="center"><input type="text" name="keywords"/></td></br>
        </tr>
        <tr>
            <td align="center"><h6>Insert Post Image</h6></td>
            <td align="center"><input type="file" name="image"/></td></br>
        </tr>
        <tr>
            <td align="center"><h6>Insert Post Content</h6></td>
            <td align="center"><textarea name="content" cols="10" rows="10"></textarea></td></br>
        </tr>
        <tr>
            <td align="center"><h6>Insert Post Summary</h6></td>
            <td align="center"><textarea name="summary" cols="5" rows="5"></textarea></td></br>
        </tr>
        <tr>
            <td align="center"><input type="submit" name="submit" value="Submit"/></td>
        </tr>
    </table>
</form>

The problem is that the $post_content variable does not insert anything into post_content field in my table however the other variables works correctly & also the success message (line 21) appears.

Here's my table structure:

post_id => int(11)

post_title => varchar(100)

post_date => date

post_author => varchar(100)

post_image => image

post_keywords => text

post_content => text

post_summary => text

</div>
  • 写回答

2条回答 默认 最新

  • duancuisan2503 2016-01-24 08:50
    关注

    The problem is that you have specified the assignment instead of comparison in the following line:

    if ($post_title=='' || $post_keywords=='' || $post_content='' || $post_author=='' || $post_summary==''){
    

    Change $post_content='' to $post_content == ''

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码