我需要使用表单编辑数据库中的值,但我很成功,
<form method='post' action='update_inv.php?id=".$row['prod_id']."'><button type='submit'>Edit</button>
不工作,它只会抛出prod_id = 1,即使按下prod_id = 2依此类推,它只显示1。
在我的update_inv.php中有这个。但仍然只有prod_id = 1。我该如何解决?
$itemid = $_GET['id'];
$qry = "SELECT * FROM inventory where prod_id = ".$itemid;
mysql_set_charset("UTF8");
$result = @mysql_query($qry);
以下是update_inv.php的完整代码
<?php
session_start();
$conn = @mysql_connect("localhost","root","12148qx3er");
$db = @mysql_select_db("buybranded");
$itemid = $_GET['id'];
$qry = "SELECT * FROM inventory where prod_id = ".$itemid;
mysql_set_charset("UTF8");
$result = @mysql_query($qry);
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
echo "<div id='page-wrap'>
<h1>Edit a Product</h1>";
while ($row=mysql_fetch_array($result)){
$prodbrand = $row['prod_brand'];
$prodname = $row['prod_name'];
$prodcategory = $row['prod_category'];
$prodprice = $row['prod_price'];
$proddesc = $row['prod_desc'];
$prodpic = $row['prod_pic'];
$prodquantity = $row['prod_quantity'];
echo "<form enctype='multipart/form-data' method='post'>";
echo "<label for='prod_brand'>Product Brand:</label><br />
<input name='prod_brand' id='prod_brand' type='text' maxlength='150' class='col1' placeholder='Auto Complete Form' value='$prodbrand'/>
<div class='clear'></div>";
echo "<label for='prod_name'>Product name:</label><br />
<input name='prod_name' id='prod_name' type='text' maxlength='150' class='col1' value='$prodname'/>
<div class='clear'></div>";
echo "<label for='prod_category'>Category:</label><br />
<select name='prod_category' class='col1'>".$row['prod_category']."
<option>Select Category</option>
<option>Compression</option>
<option>Headwear</option>
<option>Shorts</option>
<option>Yoga</optino>
<option>Swimming</option>
<option>Fitness Training</option>
<option>Water Bottles</option>
<option>Sports Socks</option>
<option>Sports Bags</option>
<option>Protein Shaker</option>
<option>Gloves</option>
<option>Splash Guards</option>
<option>Massagers</option>
<option>Sun Blocks</option>
<option>Sports Cleaners</option>
</select>
<div class='clear'></div><br>";
echo "<label for='prod_price'>Price:</label><br />
<input name='prod_price' id='prod_price' type='text' maxlength='10' class='col1' value='$prodprice'/>
<div class='clear'></div>";
echo "<label for='prod_desc'>Description: (HTML Codes are allowed)</label><br />
<textarea name='prod_desc' id='prod_desc' class='col2'>".$row['prod_desc']."</textarea>
<div class='clear'></div>";
echo "<label for='prod_pic'>Upload Image:</label><br />
<input type='file' name='prod_pic' class='col2' value=''/>
<div class='clear'></div><br>";
echo "<label for='prod_quantity'>Quantity: </label><br />
<input name='prod_quantity' id='prod_quantity' type='text' maxlength='4' class='col2' value='$prodquantity'/>
<div class='clear'></div>";
echo "<form method='post' action='updating_inv.php?id=$itemid'><button>Update this Entry!</button>";
echo '<button><a href="javascript:history.back()">Go back</a></button>';
echo "</form>";
}
echo "</div>";
?>
答案 0 :(得分:1)
您有method='post'
和$itemid = $_GET['id'];
您应该使用$itemid = $_POST['id'];