我遇到的问题是下面的查询显示成功没有错误但没有插入数据库
这是我的代码
public function uploadImg($table, $imageurl){
//path to tore the uploaded images
$target = "../images/" .basename($_FILES['image']['name']);
$image = $_FILES['image']['name'];
//echo $target;
$sql = "INSERT INTO {$table} ($imageurl) values('$target')";
$q = $this->DBcon->prepare($sql);
$q->execute();
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){
echo "uploaded successfully";
}else{
echo "error uploading";
}
}
}
答案 0 :(得分:-2)
尝试:
$sql = "insert into " . $table . " set " . $imageurl . "=" . $target;
如果存在$tabel
和$imageurl
,则会创建一条记录。如果$target
有一个字符串,它将在$ imageurl
表示的字段中注册。
答案 1 :(得分:-2)
已修复
只需从
更改您的查询即可$sql = "INSERT INTO {$table} ($imageurl) values('$target')";
到
$sql = "INSERT INTO {$table} ('$imageurl') values('$target')";