ниже приведен код для обновления: < /p>
Код: Выделить всё
if (isset($_POST['edt_Pic'])) {
$id = mysqli_real_escape_string($con, $_POST["id"]);
$file = mysqli_real_escape_string($con, $_POST['file']);
$fullname = mysqli_real_escape_string($con, $_POST['fullname']);
$filename = $_FILES['file']['name'];
$file_temp = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
if ($file_size > 1048576) {
echo "alert('Attached photo exceeds 1Mb. Kindly reduce the size.');
";
echo "window.location.href='users.php'";
} elseif (!empty($_FILES["file"]["tmp_name"])) {
$exp = explode(".", $file_name);
$ext = end($exp);
$name = $_FILES['file']['name'];
move_uploaded_file($_FILES["file"]["tmp_name"], "./users/" . $name);
$location = "./users/" . $name;
$sql = "UPDATE users
SET file = ?, location = ?, fullname = ?
WHERE id = ?";
$stmt = mysqli_prepare($con, $sql);
mysqli_stmt_bind_param($stmt, "sssi", $file, $location, $fullname, $id);
if (mysqli_stmt_execute($stmt)) {
echo "alert('Image for " . $fullname . " has updated successfully.');
";
echo "window.location.href='users.php'";
} else {
echo "alert('Oops! Something went wrong. Please try again.');
";
echo "window.location.href='users.php'";
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($con);
Подробнее здесь: https://stackoverflow.com/questions/795 ... l-database