我想使用此代码更新多个数据,但问题是,当我尝试它时,它会更新具有相同类别 ID 的整个数据,并且它应该单独更新。可能是什么解决方案。请帮忙。提前致谢 :)
<?php
if (isset($_GET['pid'])){
$view="";
$targetID = $_GET['pid'];
$sql = mysql_query("SELECT specs, category_id, price FROM specs WHERE category_id='$targetID'");
$productCount = mysql_num_rows($sql);
if($productCount > 0){
while($row = mysql_fetch_array($sql)){
$specs = $row["specs"];
$category_id = $row["category_id"];
$price = $row["price"];
$view .= '<div class="control-group">
<label class="control-label" >Specs</label>
<div class="controls">
<input type="text" placeholder="Specs" name="specs" value="'.$specs.'">
</div>
</div>
<div class="control-group">
<label class="control-label" >Price</label>
<div class="controls">
<input type="text" placeholder="Price" name="price" value="PHP '.number_format($price, 2).'">
</div>
</div>';
}
}
}
?>
<?php
if (isset($_POST['specs'])){
$pid = mysql_real_escape_string($_POST['thisID']);
$specs = mysql_real_escape_string($_POST['specs']);;
$price = mysql_real_escape_string($_POST['price']);
$sql= mysql_query("UPDATE specs SET specs='$specs', price='$price' WHERE category_id='$pid'");
header("Location: manageproducts.php");
exit();
}
?>
继承人的html。
<div class="container">
<div class="page-header">
<h1>Manage Products</h1>
</div>
<div class="row-fluid ">
<div class="box span12center-align" >
<div class="box-header well" data-original-title>
<center><h2><i class="icon-edit"></i> Edit Specifications </h2></center>
</div>
<div class="box-content" >
<form class="form-horizontal" action="" method='post'>
<fieldset>
<?php echo $view; ?>
<div class="form-actions">
<input name="thisID" type="hidden" value="<?php echo $targetID; ?>">
<button type="submit" class="btn btn-primary" name="add_product">Update Item</button>
<button class="btn">Cancel</button>
</div>
</fieldset>
</form>
</div>
</div><!--/span-->
</div><!--/row--></center>
</div>
</div>
</div>