簡體   English   中英

使用php編輯mysql表中的數據

[英]Editing data from mysql table using php

我已從表中檢索數據,並使用下面的代碼顯示了它們。

<?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>

我覺得你需要

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

編輯-使用Arif_suhail_123的答案-我沒有注意到您將PHP與HTML混在一起

您需要將rowid傳遞給Edit Link的href。

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

您正在change.php中尋找id ,但沒有在標頭中發送它。 你必須改變change

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

另外,我建議您停止使用mysql_*命令,因為它們已被棄用 ,並且將不再受支持。 請改用mysqli_*命令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM