2014-10-31 56 views
0

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

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

预先感谢您

回答

2

你忘了你id添加到您的链接

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

我想你需要

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

编辑 - 使用Arif_suhail_123的答案 - 我没有没有注意到你有PHP混合在HTML

+0

谢谢:)我不想声称虚假的荣誉!也是为了让OP得到正确的答案。返回的青睐。 – KevInSol 2014-10-31 11:28:43

0

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

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

0

您正在寻找在change.phpid,但你不发送,在头部。您必须更改change

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

另外,我建议你停止使用mysql_*命令,因为是Depreceted,并且将不再予以支持。改用mysqli_*命令。