提问者:小点点

向表中添加编辑按钮以更新mysql数据库


抱歉,这个问题已经被问了1000次了,我觉得我已经读遍了每一个帖子--但我只是没有得到它的工作。

我不熟悉mysql和html,但我已经创建了一个显示在html表中的数据库--一切正常。现在我想为每一行添加一个编辑按钮。在我的主表页上,我添加了以下代码

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

它看起来工作得很好,因为它创建的链接都显示了唯一的id(这是主键)。

无论我做什么尝试,都无法在user_edit.php上的表中显示该数据。我的当前代码是

<!DOCTYPE html>
<html>
<head>
<title>Edit</title>

</style>
</head>

<body>

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "password");
 
// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());

    if(isset($_GET['id']) && $_GET['id']!='')
    {
        $op_sql = "SELECT * FROM tracking where id=$_GET['id']"; 
        $result = $con->query($op_sql); 
        if ($result->rowCount() > 0) 
        {  
            $row = $result->fetch();
        }
    }
?>

 

<form action="update.php" method="POST">
    <input type="hidden" name="ID" value="<?php echo $_GET['id']; ?>" >
            <td><label>Freight (Air/DHL)</label></td>
            <td><input type="text" name="freight" value="<?php $row["freight"] ?> />

        <td colspan="2" align="center" ><input type ="submit" name="save" value="Submit">

</table>

</form>
</body>
</html>

如果你能告诉我哪里出了问题,我将不胜感激。


共1个答案

匿名用户

是否打印了mySQL select查询返回的响应?如果不是,那么请打印它,以确保您的查询是否正常工作。

将代码替换为

if($link === false){
  die("ERROR: Could not connect. " . mysqli_connect_error());
}else{
  if(isset($_GET['id']) && $_GET['id']!='')
  {
    $op_sql = "SELECT * FROM tracking where id=$_GET['id']"; 
    $result = $con->query($op_sql); 
    if ($result->rowCount() > 0) 
    {  
        $row = $result->fetch();
    }
  }
}