当我尝试更新图像时,我的 php 表单出现问题,希望有人能提供帮助。
表单将更新的字段提交到数据库,但是将图像路径保存到数据库并移动图像的图像上传功能在我更新时出现问题。
当我尝试编辑/更新图像时,我表中的所有记录都会被相同的数据覆盖,并且没有图像被保存。
这是我写的更新脚本:
<?php
//include database connection
include 'includes/db_connect.php';
//check any user action
$action = isset( $_POST['action'] ) ? $_POST['action'] : "";
if($action == "update"){ //if the user hit the update button
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['profileimage']['name']);
move_uploaded_file($_FILES['profileimage']['tmp_name'], $target);
//write our update query
$query = "update models
set
name = '".$mysqli->real_escape_string($_POST['name'])."',
artisttype = '".$mysqli->real_escape_string($_POST['artisttype'])."',
residence = '".$mysqli->real_escape_string($_POST['residence'])."',
agerange = '".$mysqli->real_escape_string($_POST['agerange'])."',
complexion = '".$mysqli->real_escape_string($_POST['complexion'])."',
enthnicity = '".$mysqli->real_escape_string($_POST['enthnicity'])."',
haircolor = '".$mysqli->real_escape_string($_POST['haircolor'])."',
hairlength = '".$mysqli->real_escape_string($_POST['hairlength'])."',
eyecolor = '".$mysqli->real_escape_string($_POST['eyecolor'])."',
height = '".$mysqli->real_escape_string($_POST['height'])."',
weight = '".$mysqli->real_escape_string($_POST['weight'])."',
bustsize = '".$mysqli->real_escape_string($_POST['bustsize'])."',
waistsize = '".$mysqli->real_escape_string($_POST['waistsize'])."',
hipsize = '".$mysqli->real_escape_string($_POST['hipsize'])."',
shoesize = '".$mysqli->real_escape_string($_POST['shoesize'])."',
insideleg = '".$mysqli->real_escape_string($_POST['insideleg'])."',
outsideleg = '".$mysqli->real_escape_string($_POST['outsideleg'])."',
dresssize = '".$mysqli->real_escape_string($_POST['dresssize'])."',
profileimage = '".$mysqli->real_escape_string($_FILES['profileimage']['name'])."',
brasize = '".$mysqli->real_escape_string($_POST['brasize'])."'
WHERE id='".$mysqli->real_escape_string($_REQUEST['id'])."'";
//execute the query
if( $mysqli->query($query) ) {
//if updating the record was successful
echo "User was updated.";
}else{
//if unable to update new record
echo "Database Error: Unable to update record.";
}
}
关于我哪里出错的任何提示?
谢谢。