我必须创建一个小型网站,人们可以将照片和一些文本上传到数据库中。我写的代码就是这个
<?php
$msg = "";
if (isset($_POST['upload'])){
$target = "../images/".basename($_FILES['image']['name']);
$db = mysqli_connect('xxxxx','xxxxxx''xxxxx''xxxx');
$image = $_FILES['image']['name'];
$description = $_POST['description'];
$sql = "INSERT INTO images (image, description) VALUES ('$image', '$description')";
mysqli_query($db, $sql);
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$msg = "Posted successfully";
} else {
$msg = "Post failed";
}
}
?>
和html
<!DOCTYPE html>
<html>
<head>
<title>Upload</title>
<link rel="stylesheet" type="text/css" href="../css/upload.css">
</head>
<body>
<div id="content">
<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="100000000">
<div>
<input type="file" name="image">
</div>
<div>
<textarea name="description" cols="40" rows="4" placeholder="Say somthing about this product...."></textarea>
</div>
<div>
<input type="submit" name="upload" value="Upload Image">
</div>
</form>
</div>
</body>
</html>
图片正在加载到文件夹&#34; images&#34;在服务器上,但文件不会出现在数据库中。有谁知道我做错了什么?