以PHP格式返回PHP / MySQL结果以进行编辑

时间:2014-12-09 18:58:29

标签: php html mysql

我有一个数据库,用户可以通过任意数量的预定字段(从下拉列表中选择)进行搜索。我遇到的问题是能够编辑现有记录。第一个脚本提示输入要编辑的记录ID。如果没有找到记录,则告知用户再试一次。

当找到记录时,结果将显示在HTML输入框中。然后,用户可以修改数据,点击提交和记录更新(另一个脚本)。

启用错误。这就是抛出的东西:

致命错误:在第37行调用未定义的方法mysqli_result :: fetch__assoc()(脚本的路径)

关于什么是错的任何想法?

<?php
    //Include everything but the password to connect to db
    include 'includes/connect_pw.php';

    //User supplies password on previous form
    $dbpass = $_POST['password'];     

    //User supplies id on previous form
    $rec_id = $_POST['query'];

    //Create connection to database using mysqli
    $conn = new mysqli($dbhost, $dbuser, $dbpass, $db);

    //Check connection. If error then kill process, show error and tell user to retry
    if ($conn->connect_error) {
        die ("<br><br>" . $conn->connect_error . "<p></p>Did you forget the password?");
    }

    //If no error then set select statement as variable 
    $sql = "SELECT * FROM dcr_master
            WHERE (`ID` = '".$rec_id."')";
    //Pass select ($sql) into connection ($conn) with result to ($result)
    //Set new variables to populate input boxes.  ex: $variable = $row['record field']
    $result = $conn->query($sql);

    if ($result->num_rows >=1) {
        while ($row = $result->fetch__assoc()) {
            $Server_Name = $row['Server_Name'];
            $Description = $row['Description'];
            $IP_Address = $row['IP_Address'];
            $Wiki_Link = $row['Wiki_Link'];

        }
?>
<form action="modify_dcr_3.php" method="POST">
    <input type="hidden" name="ID" value="<?=$rec_id;?>">
Server Name<input type="text" name="Server_Name" value="<?=$Server_Name;?>">
Description<input type="text" name="Description" value="<?=$Description;?>">
IP_Address<input type="text" name="IP_Address" value="<?=$IP_Address;?>">
Wiki_Link<input type="text" name="Wiki_Link" value="<?=$Wiki_Link;?>">
    <input type="submit">
</form>
<?php
        }
    else    {
        echo "<rb><br>No matching ID found.
              <p></p>Try again. Just don't use " .$rec_id. " OK?";
    }   
?>

1 个答案:

答案 0 :(得分:0)

fetch__assoc()上有双下划线,这应该只有一个下划线:fetch_assoc()。具体改变这个:

    while ($row = $result->fetch__assoc()) {
        ...
    }

要:

    while ($row = $result->fetch_assoc()) {
        ...
    }