doutang1884 2018-02-27 05:27
浏览 42

PHP表单图像上传正在工作,但文本输入不存储在数据库中

I created a form where using PHP and MySQL .Here people can input text and upload image.My image upload part is working .Image is storing in database but text does no store in database

My codes are below :

index.php

  <form action="upload.php" method="post" enctype="multipart/form-data">
      <input type="text" name="username">
       <input type="text" name="report">
        Select image to upload:
        <input type="file" name="image"/>
        <input type="submit" name="submit" value="UPLOAD"/>
    </form>

upload.php

<?php
if(isset($_POST["submit"])){
    $check = getimagesize($_FILES["image"]["tmp_name"]);

    if($check !== false){
        $image = $_FILES['image']['tmp_name'];
        $imgContent = addslashes(file_get_contents($image));

        /*
         * Insert image data into database
         */

        //DB details
        $dbHost = 'localhost';
        $dbUsername = 'root';
        $dbPassword = 'root';
        $dbName = 'testreport';

        //Create connection and select DB
        $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

        // Check connection
        if($db->connect_error){
            die("Connection failed: " . $db->connect_error);
        }

       $username = mysqli_real_escape_string($link, $_REQUEST['username']);
        $report = mysqli_real_escape_string($link, $_REQUEST['report']);
        $dataTime = date("Y-m-d H:i:s");

        //Insert image content into database
        $insert = $db->query("INSERT into images (username,report,image, created) VALUES ('$username','$report','$imgContent', '$dataTime')");
        if($insert){
            echo "File uploaded successfully.";
        }else{
            echo "File upload failed, please try again.";
        } 
    }else{
        echo "Please select an image file to upload.";
    }
}
?>
  • 写回答

3条回答 默认 最新

  • dongzhong1891 2018-02-27 05:38
    关注

    i think it should be $_POST[''] because the form method was 'post' so it will be :

       $username = mysqli_real_escape_string($_POST['username']);
       $report = mysqli_real_escape_string($_POST['report']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?