gpt4 book ai didi

php - 使用php编辑mysql表中的数据

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:45 24 4
gpt4 key购买 nike

我已经从我的表中检索数据并使用下面的代码显示它们。

<?php require_once('../Connections/bidco.php'); ?>
<body>
<table width="671" height="43" border="1" align="center">
<table width="781" height="190" align="center">
<tr>
<td height="61" colspan="4"><div align="center"><strong> Inventory </strong></div></td>
</tr>
<tr>
<td width="77" height="68"><strong>ID</strong></td>
<td width="152"><strong>Item name.</strong> </td>
<td width="253"><strong>unit price</strong> </td>

<td width="253"><strong>Update price</strong></td>

</tr>
<?php
$query=mysql_query("SELECT *FROM manuf ") or die (mysql_error());
while($row=mysql_fetch_array($query))
{
$id=$row['id'];
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['itemname']; ?></td>
<td><?php echo $row['unitprice']; ?></td>

<td><a href="change.php">change</a></td>


</tr>
<?php

}
?>
</table>
</body>
</html>

现在,此 PHP 代码应该允许我编辑在我单击“更改”时显示的各个行,但它没有选择该行。有什么解决办法吗?

<?php require_once('../Connections/bidco.php'); ?>
<?php

$id = isset($_GET['id']) ? $_GET['id'] : null;


$query=mysql_query("SELECT * FROM manuf where id='$id' ")or die(mysql_error());
$row=mysql_fetch_array($query);

?>

<form action="updateprice.php" method="post" enctype="multipart/form-data">
<table align="center">
<tr>
<td> <label><strong>Item Name</strong></label></td>
<td> <input type='text' name='itemname' value=" <?php echo $row['itemname']; ?>" />
<input type="hidden" name="id" value="<?php echo $id; ?> " /> <br /></td>
</tr>
<tr>

<td><label><strong>Unit price </strong></label></td>
<td> <input type="text" name="unitprice" value="<?php echo $row['unitprice']; ?> " /><br /></td>
</tr>

<tr>
<td>
<input type="reset" name="Reset" value="CANCEL" />
<br></td>


<td>
<input type="submit" name="Submit2" value="Update" /> </td>
</tr>
</table>
</form>
</body>
</html>

提前致谢

最佳答案

您忘记将您的 id 添加到您的链接中

<td><a href="change.php?id=<?php echo $row['id']?>">change</a></td>

关于php - 使用php编辑mysql表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26673033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com