图像已上传但未存储

时间:2016-02-17 03:46:36

标签: php mysql image-upload

我正在尝试将图像名称与其他数据一起存储在数据库中但无法存储。数据库中没有插入任何内容。但是当我在db config之前关闭brace}时,图像会上传到目录中。但是当我在插入后关闭函数括号}时,我调用了一个未定义的函数upload()。这是代码:

$imagesub = isset( $_FILES['image'] );

if ( $imagesub ) 
{
    $output=upload();
}
return $output;
function upload()
{

    include_once "class.php";

    $uploader = new Uploader( "image" );

    $uploader->saveIn("images");

    $fileUploaded = $uploader->save();



$db = new mysqli("localhost", "root","","learndb");

if ($db->connect_error) {
    die("Connection failed this is the error: " . $db->connect_error);
}

$stmt = $db->prepare("INSERT INTO studentrecords (Name, email, Phone, school,dob,father,feereceived,due,image) VALUES (?,?,?,?,?,?,?,?,?)");

if($stmt)
{
    $stmt->bind_param("ssisssiis",$name,$email,$phone,$school,$dob,$father,$feereceived,$due,$fileUploaded);
        $stmt->execute();
    $out="<center>information entered.</center>";
        echo "$out";
}
else
{

    $out="DATABASE ERROR!!!";
    echo "$out";
}
      return $out;
}

这是函数save()

public function save(){
    $folderIsWriteAble = is_writable( $this->destination );
    if( $folderIsWriteAble ){
        $name = "$this->destination/$this->filename";
        if($succes = move_uploaded_file( $this->fileData, $name ))
        {
            return $name;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

@Micky你在插入查询中只定义了9个字段,但是你在'bind_param()中传递了10个参数。

$stmt->bind_param("ssisssiis",$name,$email,$phone,$school,$dob,$father,$feereceived,$due,$fileUploaded);

应该是

$stmt->bind_param($name,$email,$phone,$school,$dob,$father,$feereceived,$due,$fileUploaded);

如果它没有解决您的问题,那么var_dump您的$ fileUploaded变量并确保您为用于存储文件名的列定义了兼容的数据类型。