<?php
ob_start();
include ('include/config_db.php');
//include ('include/header.php');
//include ('include/sidebar.php');
$pro_id = $_REQUEST['pro_id'];
$product_query= mysql_query("select * from product where pro_id='$pro_id'");
$product_fetch=mysql_fetch_assoc($product_query);
if(isset($_REQUEST['save']))
{
$sub_id = $_REQUEST['sub_id'];
$cat_id= $_REQUEST['abc'];
$pro_name = $_REQUEST['pro_name'];
$pro_desc = $_REQUEST['pro_desc'];
$pro_price = $_REQUEST['pro_price'];
$pro_quant = $_REQUEST['pro_quant'];
$pro_offer = $_REQUEST['pro_offer'];
$product_query = mysql_query("update product set sub_id = '$sub_id' , cat_id = '$cat_id' ,pro_name = '$pro_name',pro_desc = '$pro_desc', pro_price = '$pro_price' , pro_quant = '$pro_quant' , pro_offer = '$pro_offer' where pro_id = $pro_id ");
if(!$sql)
{
die("User Is Not Update ". mysql_error());
}
header("Location: products.php");
}
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Edit Product Details Here.
</h1>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<!-- left column -->
<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Edit Product</h3>
</div><!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" method="post">
<div class="box-body">
<div class="form-group">
<label class="col-sm-4 control-label ">Category</label>
<div class="col-sm-6">
<select class="form-control" onChange="get_subcat(this.value)" name="abc">
<option value=""> Select Category </option>
<?php
$cat=mysql_query("select * from category");
while($fetch = mysql_fetch_assoc($cat))
{
?>
<option value="<?php echo $fetch['cat_id'];?>"
<?php if( $fetch['cat_id'] == $product_fetch['cat_id'] ) { echo "selected"; }?> >
<?php echo $fetch['cat_name'];?>
</option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="inputText" class="col-sm-4 control-label">Sub Category Name</label>
<div class="col-sm-6">
<select class="form-control" id="sub_id" name="sub_id" type="text">
<?php
$sub_category = mysql_query("select * from sub_category where cat_id = ".$product_fetch['cat_id']);
while($sub_fetch = mysql_fetch_assoc($sub_category))
{
?>
<option ><?php echo $sub_fetch['sub_name']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Product Name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="inputtext" placeholder="Enter Product Name" required
name="pro_name" value="<?php echo $product_fetch['pro_name']; ?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Product Description </label>
<div class="col-sm-6">
<input type="text" class="form-control" id="inputtext" placeholder="Enter Product Description" required
name="pro_desc" value=<?php echo $product_fetch['pro_desc']; ?> >
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Product Price</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="inputtext" placeholder="Enter Product Price" required
name="pro_price" value=<?php echo $product_fetch['pro_price']; ?> >
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Total Product Quantity</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="inputtext" placeholder="Enter Product Quantity" required
name="pro_quant" value=<?php echo $product_fetch['pro_quant']; ?>>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Product Discount</label>
<div class="col-sm-6">
<select class="form-control" name="pro_offer">
<option <?php if( $product_fetch['pro_offer'] == "10%") { echo "selected";} ?> >10%</option>
<option <?php if( $product_fetch['pro_offer'] == "20%") { echo "selected";} ?> >20%</option>
<option <?php if( $product_fetch['pro_offer'] == "30%") { echo "selected";} ?> >30%</option>
<option <?php if( $product_fetch['pro_offer'] == "40%") { echo "selected";} ?> >40%</option>
<option <?php if( $product_fetch['pro_offer'] == "50%") { echo "selected";} ?> >50%</option>
<option <?php if( $product_fetch['pro_offer'] == "60%") { echo "selected";} ?> > 60%</option>
<option <?php if( $product_fetch['pro_offer'] == "70%") { echo "selected";} ?> > 70%</option>
<option <?php if( $product_fetch['pro_offer'] == "80%") { echo "selected";} ?> >80%</option>
<option <?php if( $product_fetch['pro_offer'] == "90%") { echo "selected";} ?> > 90%</option>
<option <?php if( $product_fetch['pro_offer'] == "100%") { echo "selected";} ?> > 100%</option>
</select>
</div>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<a href="products.php"> <button type="button" class="btn btn-default">Cancel</button></a>
<button type="submit" class="btn btn-info pull-right" name="save">Save Changes</button>
</div><!-- /.box-footer -->
</form>
</div><!-- /.box -->
</div>
</div>
</section>
</div><!-- /.content-wrapper -->
<?php
include ('include/footer.php');
ob_flush();
?>
在更新的整个操作中,此错误将作为输出:
用户不更新无法添加或更新子行:外键 约束失败(
ayur
。product
,CONSTRAINTforeign_sub_id
FOREIGN KEY(sub_id
)REFERENCESsub_category
(sub_id
)ON DELETE CASCADE ON UPDATE CASCADE)。
请尽快帮我解决这个疑问!!