我正在尝试制作一个页面,用于将图像上传到服务器,并将信息存储在SQL数据库中。但它的SQL部分不起作用。有人可以帮我找一下我的错误吗?
PHP部分:
include 'db.php';
if(isset($_POST['submit']))
{
$uploadfile=$_FILES["upload_file"]["tmp_name"];
$folder="images/";
move_uploaded_file($_FILES["upload_file"]["tmp_name"],"$folder".$_FILES["upload_file"]["name"]);
$conn = new PDO('mysql:host=localhost;dbname=storfanger2017', $username, $password);
$query = "INSERT INTO stor_2017 (image_name, image_size, image_type, image_content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
query($query) or die('Error, query failed');
}
HTML部分:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<script>
$(document).ready(function() {
$('form').ajaxForm(function() {
});
});
</script>
</head>
<body>
<div id="wrapper">
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="upload_file" name="upload_file" />
<input type="submit" name='submit_image' value="Upload Image"/>
</form>
</div>
</body>
</html>
上传到服务器工作正常,但遗憾的是sql部分仍然给我带来很多麻烦。