我正在尝试通过插入新图片来更新我的数据库。 我正在运行代码时没有错误,但图片没有进入数据库。以下是我的代码:
<?php
error_reporting( ~E_NOTICE );
require_once 'dbcon.php';
if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
{
$id = $_GET['edit_id'];
$stmt_edit = $DB_con->prepare('SELECT audit_id, audit_id, descr, correction, status FROM correction WHERE correction_id =:cid');
$stmt_edit->execute(array(':cid'=>$id));
$edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
extract($edit_row);
}
else
{
header("Location: correction.php");
}
if(isset($_POST['btn_save_updates']))
{
$audit_id = $_POST['audit_id'];
$descr = $_POST['descr'];
$status = $_POST['status'];
$imgFile = $_FILES['image']['name'];
$tmp_dir = $_FILES['image']['tmp_name'];
$imgSize = $_FILES['image']['size'];
if($imgFile)
{
$upload_dir = 'images/';
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION));
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif');
$userprofile = rand(1000,1000000).".".$imgExt;
if(in_array($imgExt, $valid_extensions))
{
if($imgSize < 5000000)
{
unlink($upload_dir.$edit_row['correction']);
move_uploaded_file($tmp_dir,$upload_dir.$correction);
}
else
{
$errMSG = "Sorry, Your File Is Too Large To Upload. It Should Be Less Than 5MB.";
}
}
else
{
$errMSG = "Sorry, only JPG, JPEG, PNG & GIF Extension Files Are Allowed.";
}
}
else
{
$correction = $edit_row['correction'];
}
if(!isset($errMSG))
{
$stmt = $DB_con->prepare('UPDATE correction SET correction_id=:cid, audit_id=:aid, descr=:descr, correction=:pic, status=:stat WHERE correction_id=:cid');
$stmt->bindParam(':aid',$audit_id);
$stmt->bindParam(':descr',$descr);
$stmt->bindParam(':pic',$correction);
$stmt->bindParam(':stat',$status);
$stmt->bindParam(':cid',$id);
if($stmt->execute()){
?>
<script>
alert('Successfully Updated...');
window.location.href='correction.php';
</script>
<?php
}
else{
$errMSG = "Sorry. Could Not Be Updated!";
}
}
}
?>
<!DOCTYPE HTML>
<html lang = "eng">
<head>
<meta charset = "UTF-8">
<link rel = "stylesheet" type = "text/css" href = "css/bootstrap.css" />
<link rel = "stylesheet" type = "text/css" href = "css/jquery.dataTables.css" />
<meta name = "viewport" content = "width=device-width, initial-scale=1" />
<title>Audit Management System</title>
</head>
<body>
<nav class = "navbar navbar-inverse">
<div class = "container-fluid">
<div class = "navbar-header">
<a class = "navbar-brand">Audit Management System</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Settings <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="logout.php">Logout</a></li>
</ul>
</li>
</ul>
</div>
</nav>
<div class = "container-fluid">
<ul class="nav nav-pills">
<li><a href="auditee_home.php">Home</a></li>
<li><a href="schedule_v.php">Schedule</a></li>
<li><a href="generate.php">Generate Report</a></li>
<li class="active"><a href="correction.php">Correction</a></li>
</ul>
<br />
<div class = "col-md-12 well">
<a class = "btn btn-success" href = "correction.php"><span class = "glyphicon glyphicon-hand-right"></span> Back</a>
<br/>
<br/>
<div class = "alert alert-warning">Correction</div>
<div class = "row">
<div class = "col-md-2 ">
</div>
<div class = "col-md-2">
</div>
<div class = "col-md-4">
<?php
$correction_id=$_GET['edit_id'];
$acc_query = $conn->query("SELECT * FROM `correction` WHERE correction_id = '$_REQUEST[edit_id]'") or die(mysqli_error());
$acc_fetch = $acc_query->fetch_array();
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="correction_id" value="<?php echo $correction_id; ?>">
<div class = "form-group">
<label>Audit ID</label>
<input name="audit_id" id = "audit_id" type = "text" value = "<?php echo $acc_fetch['audit_id']?>" class = "form-control" readonly="readonly"/>
</div>
<div class = "form-group">
<label>Description</label>
<input name="descr" type = "text" id = "descr" type = "text" value= "<?php echo $acc_fetch['descr']?>" class = "form-control" readonly="readonly"/>
</div>
<div class = "form-group">
<label>Correction</label>
<input name="image" type = "file" class = "input-group" accept="image/*" />
</div>
<div class = "form-group">
<label>Status</label>
<input name="status" type = "text" id = "descr" type = "text" value= "<?php echo $acc_fetch['status']?>" class = "form-control" readonly="readonly"/>
</div>
<div id = "loading">
</div>
<br />
<div class = "form-group">
<button type="submit" name="btn_save_updates" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-save"></span> Save</button>
<a class="btn btn-warning" href="home.php"> <span class="glyphicon glyphicon-remove"></span> Cancel</a>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
任何形式的帮助将不胜感激:)
答案 0 :(得分:0)
似乎参数的数量在prepare语句中不匹配。
<?php
$stmt = $DB_con->prepare('UPDATE correction SET correction_id=:cid, audit_id=:aid, descr=:descr, correction=:pic, status=:stat WHERE correction_id=:cid2');
$stmt->bindParam(':cid',$id);
$stmt->bindParam(':aid',$audit_id);
$stmt->bindParam(':descr',$descr);
$stmt->bindParam(':pic',$correction);
$stmt->bindParam(':stat',$status);
$stmt->bindParam(':cid2',$id);