<?php
@include './html_header.php';
@include './connection.php';
$myprid = $_GET['prid'];
$sql = "SELECT * FROM products WHERE id = '".$myprid."'";
$result = mysql_query($sql);
$rs = mysql_fetch_array($result);
$sqlc = "SELECT * FROM categories";
$resultc = mysql_query($sqlc);
?>
<h2>แก้ไขสินค้า</h2>
<form method="post" action="products_edit_process.php" enctype="multipart/form-data">
<input type="hidden" name="p[prid]" value="<?php echo $rs['id'];?>" />
<table>
<tr>
<td>ประเภทสินค้า:</td>
<td>
<select name="p[category_id]">
<?php while ($rsc = mysql_fetch_array($resultc)) { ?>
<option value="<?php echo $rsc['id'];?>" <?php if($rsc['id']==$rs['category_id']){ ?> selected="selected" <?php }?>><?php echo $rsc['category']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>ชื่อสินค้า</td>
<td><input type="text" name="p[product_name]" value="<?php echo $rs['product_name'];?>" /></td>
</tr>
<tr>
<td>รายละเอียดสินค้า:</td>
<td><textarea name="p[product_detail]" cols="50" rows="8"><?php echo $rs['product_detail'];?></textarea>
</tr>
<tr>
<td>ราคา:</td>
<td><input type="text" name="p[product_price]" value="<?php echo $rs['product_price'];?>" /></td>
</tr>
<tr>
<td>รูป:</td>
<td><img src="<?php echo $rs['product_img'];?>" width="200" /> <br />
<input type="file" name="fileUpload" />
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="แก้ไขสินค้า" /></td>
</tr>
</table>
</form>
<?php
include '/.html_footer.php';
$sql = "UPDATE products SET WHERE id =
category_id='" . $myp['category_id'] . "',
product_name='" . $myp['product_name'] . "',
product_detail='" . $myp['product_detail'] . "',
product_img='" . $target . "',
product_price='" . $myp['product_price'] . "',
modified='" . date("Y-m-d H:i:s") . "'";
} else {
$sql = "UPDATE products SET WHERE id =
category_id='" . $myp['category_id'] . "',
product_name='" . $myp['product_name'] . "',
product_detail='" . $myp['product_detail'] . "',
product_price='" . $myp['product_price'] . "',
modified='" . date("Y-m-d H:i:s") . "'";
Where ต้องใส่หลังสุดนะครับ รูปแบบคือ UPDATE xxx SET xxx=xxx WHERE xxx=xxx
$sql = "UPDATE products SET
category_id='" . $myp['category_id'] . "',
product_name='" . $myp['product_name'] . "',
product_detail='" . $myp['product_detail'] . "',
product_img='" . $target . "',
product_price='" . $myp['product_price'] . "',
modified='" . date("Y-m-d H:i:s") . "'";
WHERE id = '".$myp['prid']."'";
} else {
$sql = "UPDATE products SET
category_id='" . $myp['category_id'] . "',
product_name='" . $myp['product_name'] . "',
product_detail='" . $myp['product_detail'] . "',
product_price='" . $myp['product_price'] . "',
modified='" . date("Y-m-d H:i:s") . "'
WHERE id = '".$myp['prid']."'";
id คือ id ของ primary key ของ record ที่ต้องการแก้ไข ส่งมาจากฟอร์ม <input type="hidden" name="p[prid]" value="<?php echo $rs['id'];?>" />
ตอบ/อธิบาย