【发布时间】:2018-05-21 06:20:48
【问题描述】:
除了 $sqlImg(它应该将上传的图像插入到表中)之外的所有东西都在工作。有人可以向我解释为什么它不起作用吗?或者,如果有另一种可行的方法,我很想听听。下面的文件是我的upload.inc.php。我打算将图像插入到我的表中后,在另一个名为 home.php 的文件中回显该图像。
<?php
if (!isset($_SESSION)) {
session_start();}
include_once 'includes/dbh.inc.php';
$id = $_SESSION['key'];
if (isset($_POST['submitFile'])) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if (in_array($fileActualExt, $allowed)) {
if ($fileError == 0) {
if ($fileSize < 1000000) {
$fileNameNew = "profile".$id.".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
$sql = "UPDATE profileimg SET status=0 WHERE userid='$id';";
mysqli_query($conn, $sql);
$sqlImg = "INSERT INTO profileimg (image) WHERE userid='$id' VALUES ($fileNameNew);";
mysqli_query($conn, $sqlImg);
header("Location: home.php?upload=success");
}
else { echo "Sorry, your file size is too big.";}
}
else { echo "Oops, an error occurred!";}
}
else { echo "Please upload png and jpg files only.";}
}
【问题讨论】:
标签: php mysqli insert-into