0

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

4 Answers 4

2

Your forget to add you id to your link

<td><a href="change.php?id=<?php echo $row['id']?>">change</a></td>
Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Thank you :) I would not want to claim false kudos! and also so that the OP will get the correct answer. Returned favour.
0

You need to pass rowid to href of Edit Link.

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.