我的编辑页面遇到问题。肯定有一些我想念的地方。
我可以完美地添加和查看我的特色产品,但是一旦我将其中一张图像编辑为另一张图像,其他所有5张图像就会中断,然后在我查看时,它们也会在此处中断。 / p>
这是视图页面上的样子
我要做的就是单独更新每个图像,而不会影响其他图像。
这是我的编辑页面代码
<?php session_start(); ?>
<?php
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: welcome.php");
exit;
}
?>
<?php
require_once 'connect.php';
require_once 'editfeaturedheader.php';
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="container">
<?php
if(isset($_POST['update'])){
$image1 = $con->real_escape_string($_FILES['image1']['name']);
$image2 = $con->real_escape_string($_FILES['image2']['name']);
$image3 = $con->real_escape_string($_FILES['image3']['name']);
$image4 = $con->real_escape_string($_FILES['image4']['name']);
$image5 = $con->real_escape_string($_FILES['image5']['name']);
$image6 = $con->real_escape_string($_FILES['image6']['name']);
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$sql = $con->prepare("UPDATE featuredproducts SET image1 = ?, image2 = ?, image3 = ?, image4 = ?, image5 = ?, image6 = ? WHERE featuredproduct_id = ?");
$sql->bind_param("ssssssi", $image1, $image2, $image3, $image4, $image5, $image6, $id);
if($sql->execute()) {
echo "<div class='alert alert-success'>Successfully updated product</div>";
}else{
echo "<div class='alert alert-danger'>Error: There was an error while updating product info</div>";
}
}
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$sql = $con->prepare("SELECT * FROM featuredproducts WHERE featuredproduct_id = ?");
$sql->bind_param('i', $id);
$sql->execute();
$result = $sql->get_result();
if($result->num_rows < 1){
header('Location: index.php');
exit;
}
$row = $result->fetch_assoc();
?>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="box">
<h3><i class="glyphicon glyphicon-plus"></i> Modify Featured Products</h3><br>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" value="<?php echo $row['featuredproduct_id']; ?>" name="featuredproductid">
<label for="name">Image 1</label><br><br>
<span><?php echo '<img src="Images/'. $row['image1'], '" />'?></span><br><br>
<input type="file" name="image1" id="image1" value="<?php echo $row['image1']; ?>" class="form-control"><br>
<label for="name">Image 2</label><br><br>
<span><?php echo '<img src="Images/'. $row['image2'], '" />'?></span><br><br>
<input type="file" name="image2" id="image2" value="<?php echo $row['image2']; ?>" class="form-control"><br>
<label for="name">Image 3</label><br><br>
<span><?php echo '<img src="Images/'. $row['image3'], '" />'?></span><br><br>
<input type="file" name="image3" id="image3" value="<?php echo $row['image3']; ?>" class="form-control"><br>
<label for="name">Image 4</label><br><br>
<span><?php echo '<img src="Images/'. $row['image4'], '" />'?></span><br><br>
<input type="file" name="image4" id="image4" value="<?php echo $row['image4']; ?>" class="form-control"><br>
<label for="name">Image 5</label><br><br>
<span><?php echo '<img src="Images/'. $row['image5'], '" />'?></span><br><br>
<input type="file" name="image5" id="image5" value="<?php echo $row['image5']; ?>" class="form-control"><br>
<label for="name">Image 6</label><br><br>
<span><?php echo '<img src="Images/'. $row['image6'], '" />'?></span><br><br>
<input type="file" name="image6" id="image6" value="<?php echo $row['image6']; ?>" class="form-control"><br>
<br>
<input type="submit" name="update" class="btn btn-success button2" value="Update">
</form>
</div>
</div>
</div>
</div>
</body>
</html>
这是我的查看页面代码
<?php session_start(); ?>
<?php
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: welcome.php");
exit;
}
?>
<?php
require_once 'connect.php';
require_once 'viewfeaturedheader.php';
require_once 'previewheader.php';
echo "<div class='container'>";
if( isset($_POST['delete'])){
if($sql = $con->prepare("DELETE FROM featuredproducts WHERE featuredproduct_id = ?"))
{
$sql->bind_param("i", $_POST['featuredproductid']);
$sql->execute();
$sql->close();
}
else{
echo ("<div class='alert alert-danger'>Error: There was an error while deleting product</div>");
}
echo ("<div class='alert alert-success'>Successfully deleted product</div>");
}
$sql = "SELECT * FROM featuredproducts";
$result = $con->query($sql);
if( $result->num_rows > 0)
{
?>
<h2>List of all Featured Products</h2>
<table class="table table-bordered table-striped">
<tr>
<td style="text-align: center;">Image 1</td>
<td style="text-align: center;">Delete</td>
<td>EDIT</td>
</tr>
<?php
while( $row = $result->fetch_assoc()){
echo "<form action='' method='POST'>"; //added
echo "<input type='hidden' value='". $row['featuredproduct_id']."' name='featuredproductid' />"; //added
echo "<tr>";
echo "<td>".'<img src="Images/', $row['image1'], '" />' . "</td>";
echo "<td><input type='submit' name='delete' value='Delete' class='btn btn-danger' /></td>";
echo "<td><a href='editfeatured.php?id=".$row['featuredproduct_id']."' class='btn btn-info'>Edit</a></td>";
echo "</tr>";
echo "<tr>";
echo "<td>".'<img src="Images/', $row['image2'], '" />' . "</td>";
echo "<td><input type='submit' name='delete' value='Delete' class='btn btn-danger' /></td>";
echo "<td><a href='editfeatured.php?id=".$row['featuredproduct_id']."' class='btn btn-info'>Edit</a></td>";
echo "</tr>";
echo "<tr>";
echo "<td>".'<img src="Images/', $row['image3'], '" />' . "</td>";
echo "<td><input type='submit' name='delete' value='Delete' class='btn btn-danger' /></td>";
echo "<td><a href='editfeatured.php?id=".$row['featuredproduct_id']."' class='btn btn-info'>Edit</a></td>";
echo "</tr>";
echo "<tr>";
echo "<td>".'<img src="Images/', $row['image4'], '" />' . "</td>";
echo "<td><input type='submit' name='delete' value='Delete' class='btn btn-danger' /></td>";
echo "<td><a href='editfeatured.php?id=".$row['featuredproduct_id']."' class='btn btn-info'>Edit</a></td>";
echo "</tr>";
echo "<tr>";
echo "<td>".'<img src="Images/', $row['image5'], '" />' . "</td>";
echo "<td><input type='submit' name='delete' value='Delete' class='btn btn-danger' /></td>";
echo "<td><a href='editfeatured.php?id=".$row['featuredproduct_id']."' class='btn btn-info'>Edit</a></td>";
echo "</tr>";
echo "<tr>";
echo "<td>".'<img src="Images/', $row['image6'], '" />' . "</td>";
echo "<td><input type='submit' name='delete' value='Delete' class='btn btn-danger' /></td>";
echo "<td><a href='editfeatured.php?id=".$row['featuredproduct_id']."' class='btn btn-info'>Edit</a></td>";
echo "</tr>";
echo "</form>"; //added
}
?>
</table>
<?php
}
else
{
echo "<br><br>No Record Found";
}
?>
任何帮助将不胜感激,因为我在产品页面上遇到了相同的问题,即产品图片和pdf链接执行相同的操作,我必须同时更新两者,如果我更新一个或另一个会破坏一个或另一个。它让我发疯。