dongsui4658 2014-12-15 09:42
浏览 10
已采纳

无法传递参数。 添加图像根名称$ _Files以插入到db

Im having trouble adding the file root of the uploaded file to my DB. I have been told to try the following below but im getting the error and no longer getting a reply :Cannot pass parameter 8 by reference in send_config.php on line 47 is the following line. '".$target_file."');


send_config.php


$stmt = $conn->prepare("INSERT INTO detail (company_name,ref,website,email,tel,message,location) VALUES (?, ?, ?, ?, ?, ?, ?)");
                            $stmt->bind_param('sssssss', 
                                $_REQUEST['company_name'],
                                $_REQUEST['ref'],
                                $_REQUEST['website'],
                                $_REQUEST['email'],
                                $_REQUEST['tel'],
                                $_REQUEST['message'],
                                '".$target_file."');

                            include 'mail2.php';                       

                            if($stmt->execute()) {
                                echo "Database Successfully Updated.";
                            } else {
                                echo "Error To Update Database: " . $stmt->error;
                            };

email.php


$to = 'test@gmail.com';
    $subject = 'Website Submission';
    $company_name = $_POST['company_name'];
    $ref = $_POST['ref'];
    $website = $_POST['website'];
    $email = $_POST['email'];
    $tel = $_POST['tel'];
    $message = $_POST['message'];

    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    // Check if image file is a actual image or fake image
    if(isset($_POST["submit"])) {
        $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
        if($check !== false) {
            echo "<p>File is an image - " . $check["mime"] . ".</p>";
            $uploadOk = 1;
        } else {
            echo '<p style="color:red;">File is not an image.</p>';
            $uploadOk = 0;

        }
    }
    // Check if file already exists
    if (file_exists($target_file)) {
        echo '<p style="color:red;">Sorry, file already exists.</p>';
        $uploadOk = 0;
    }
    // Check file size
    if ($_FILES["fileToUpload"]["size"] > 500000) {
        echo '<p style="color:red;">Sorry, your file is too large.</p>';
        $uploadOk = 0;
    }
    // Allow certain file formats
    if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
    && $imageFileType != "gif" ) {
        echo '<p style="color:red;">Sorry, only JPG, JPEG, PNG & GIF files are allowed.</p>';
        $uploadOk = 0;

    }
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        echo '<p style="color:red;">Sorry, your file was not uploaded.</p>';
    // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
        } else {
            echo '<p style="color:red;">Sorry, there was an error uploading your file.</p>';
        }
    }
  • 写回答

1条回答 默认 最新

  • douduan9129 2014-12-15 09:46
    关注

    You just need to add $target_file as a parameter, not like a string. You specified that is a string when you sad sssssss. Try this:

    $stmt->bind_param('sssssss', $_REQUEST['company_name'], $_REQUEST['ref'], $_REQUEST['website'], $_REQUEST['email'], $_REQUEST['tel'], $_REQUEST['message'], $target_file);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊