【发布时间】:2017-01-04 02:51:33
【问题描述】:
我有一个上传图片的按钮,每次我上传图片时,图片都不会保存在数据库中,并且没有给出错误,
这是我的代码:
<td>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" required>
<button type="submit" name="files" class="btn btn-primary btn-xs">
Submit
</button>
<?php
if(isset($_POST['files']))
{
$userid = $row['stall_id'];
$a = $_FILES['file']['name'];
$ab = $_FILES['file']['tmp_name'];
$location = "".$a;
move_uploaded_file($ab, "../pictures/".$location);
$sql2 = $conn->prepare("UPDATE stall SET file = ? WHERE stall_id = ?");
$sql2->execute(array($location,$userid));
if($sql){
echo '
<script>
window.location = "stalls.php"
</script>';
}
}
?>
</td>
【问题讨论】:
-
文件真的上传了吗?
-
@Dagon 它只提交但不保存在数据库中。
-
是的,但是文件,上传了吗?
-
你使用了错误的变量,不知道你为什么使用
$location = "".$a; -
我也没有看到结束
</form>标记。加上<form>不能是<table>的孩子。您有错误和一些未知数。