简体   繁体   中英

Editing data from mysql table using php

I have retrieved data from my table and displayed them using the code below.

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

Now this PHP code is supposed to allow me to edit individual rows that have been displayed when i click on 'change' but it it not selecting the row. Any ideas how to solve this?

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

Thank you in advance

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

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

I think you need

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

Edit - use Arif_suhail_123's answer - I did not notice you have PHP mixed in with HTML

您需要将rowid传递给Edit Link的href。

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

You are looking for id in change.php , but you are not sending that in the header. You must change change with

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

Also, I suggest you STOP using mysql_* commands, since the are Depreceted , and will no longer be supported. Use mysqli_* commands instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM