我收到了img_description
,但我的img_name
仍为空。
基本的PHP代码
$msg = "";
if(isset($_POST['upload'])) {
$target = "images/".basename($_FILES['image']['name']); // get error here
$image = $_FILES['image']['name']; // get error here
$text = $_POST['text'];
$sql = "INSERT into images (img_name, img_description) values ('$image', '$text')";
$smt = $heidisql->prepare($sql);
$smt->execute();
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) { //error here
$msg = "Image upload sucessfully";
}else {
$msg = "Image failed to upload properly";
}
我的基本表格
<form method="POST" action="checkout.php" enctype="multipart/form-date">
<input type="hidden" name="size" value="1000000">
<div>
<input type="file" name="image">
</div>
<div>
<textarea name="text" cols="40" rows="4" placeholder="img text decription" ></textarea>
</div>
<div>
<input type="submit" name="upload" value="upload img">
</div>
</form>
表:图片,属性 - &gt; img_id,img_name,img_description
错误:未定义的索引:图片
答案 0 :(得分:1)
您的表单标记中的enctype
中有拼写错误。
更改
multipart/form-date
到
multipart/form-data
答案 1 :(得分:0)
您有写错误 enctype =“multipart / form-date”请改用 enctype =“multipart / form-data”。