dream890110 2016-06-10 14:28
浏览 12
已采纳

使用id功能编辑产品页面

On a web app i'm making, I have an edit page which is obviously where users edit info on already existing products, it uses PHP/ MySQL. My edit page is ALMOST working exactly how I want it too. I have a drop-down populated from the SQL database, and I can edit the product info via the text-boxes. The only problem I have is that I do not know how to edit the products via the ID which changes as the products are selected.. I instead have to manually set a static value in the PHP code, I was just wondering how I could do this? I'm thinking GET could be used but not entirely sure.. I'll post pictures and code below.. thanks.

enter image description here

The ID changes to the corresponding product ID as I select a product from the dropdown

enter image description here

As you can see I have to type in the ID in the php..

so basically i was trying to get it to change the product to edit as i select them from the dropdown..

hope i wasnt too confusing, thanks!

$conn = new mysqli('', '', '', '') 
or die ('Cannot connect to db');

$result = $conn->query("select ID, NAME from PRODUCTS");

?><div align="left"><?
print  "<h3>EDIT PRODUCT</h3>"; 
print "<strong>SELECT PRODUCT:</strong>";
print "<br><br>";

print "<form method='GET' id='frm_product'>";
print   "<select name='ID' OnChange='$(\"#frm_product\").submit();'>";
    while ($row = $result->fetch_assoc()) 
    {
        print "<option value='$row[ID]'>$row[NAME]</option>";
    }
print "</select>";
print "</form>";

?>
<form method='POST'>
<h3>PRODUCT:</h3>
<input type='textbox' name='product' value='<?php echo $product['product'] ?     >'> 

<h3>BARCODE:</h3>
<input type='textbox' name='barcode' value='<?php echo $product['barcode']; ?>'>

<h3>TYPE:</h3>
<select name="type">
    <option value=""></option>
    <option value="A">A</option> 
    <option value="B">B</option>
    <option value="C">C</option>
</select>
<br><br>
<input type='submit' value='Save Changes' name=submitform> 
</form>

<? 
if (isset($_POST['submitform']))
{
$namechange = $_POST[product];
$barcodechange = $_POST[barcode];
$typechange = $_POST[type];

$sql = "UPDATE PRODUCTS SET 
                    NAME='$namechange' 
                    ,BARCODE='$barcodechange'
                    ,TYPE='$typechange' 
                 WHERE ID='79'";

if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
}
  • 写回答

3条回答 默认 最新

  • drt96856 2016-06-10 14:43
    关注

    Cant you set:-

    $productID = $_GET['ID'];

    And then change the 79 on the update script to $productID?

    Hopefully I understood the question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛