【发布时间】:2016-05-28 14:46:05
【问题描述】:
我正在尝试将图像名称与其他数据一起存储在数据库中,但无法存储。数据库中没有插入任何内容。但是当我在 db config 之前关闭大括号 } 时,图像会上传到目录中。但是当我在插入后关闭函数大括号 } 时,我调用了一个未定义的函数 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;
}
}
}
【问题讨论】:
-
$uploader->save();是否返回文件名?你能在函数里面添加什么吗? -
@roullie 我已经添加了。
-
你收到
DATABASE ERROR!!!了吗?你检查过绑定和/或执行的错误吗? -
@chris85 我没有收到那个错误。我收到一个白色的空白新页面。
-
好的,PHP 错误日志中有什么?
标签: php mysql image-upload