douqian6315 2016-10-17 01:24
浏览 11

无法将post和images值添加到数据库中

i'm trying to add text and images using

Image is successfully added into folder path. but the value of text and images did not add into database

<?php

    function insertpost(){
        global $connect;
        if(isset($_POST['sendpost']))
        {
            $title                 = mysqli_real_escape_string($connect,$_POST["title"]);
            $target_image          = "images/".basename($_FILES['post_image']['name']);
            $post_image            = $_FILES['post_image']['name'];

            $insert_post_and_image = "INSERT INTO table(title, image) VALUES ('$title','$post_image')";
            mysqli_query($connect, $insert_post_and_image);

                if(move_uploaded_file($_FILES['post_image']['tmp_name'], $target_image))
                {
                        echo "<h3>Posted to timeline!</h3>";
                }
        }   
    }
?>

html code

<form action="" method="post" id="form" enctype="multipart/form-data">
                        <input type="text" name="title"/>
                        <input type="file" name="post_image"/>
                        <input type="submit" name="sendpost" value="POST"/> 
</form>

any solution? thanks

  • 写回答

2条回答 默认 最新

  • duanlujiaji10335 2016-10-17 01:33
    关注

    I think you have mistake in table name in your query .Just replace table with your actual table name.For example if you have defined table name as user then your query must be

    $insert_post_and_image = "INSERT INTO user(title, image) VALUES ('$title','$post_image')";
    

    Also you can check error using

    if (mysqli_query($connect, $insert_post_and_image)) {
        echo "success";
    } else {
        echo "Error: " . mysqli_error($connect);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数