简体   繁体   English

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

[英]Return PHP/MySQL results in HTML form for editing

I have a database that users can search by any number of predetermined fields (chosen from a drop down). 我有一个数据库,用户可以按任意数量的预定字段进行搜索(从下拉列表中选择)。 The problem I'm having is being able to edit existing records. 我遇到的问题是能够编辑现有记录。 The first script prompts for the record ID to edit. 第一个脚本提示输入要编辑的记录ID。 If no record is found the user is told to try again. 如果未找到任何记录,则提示用户重试。

When a record is found the results are suppose to display in HTML input boxes. 找到记录后,结果将显示在HTML输入框中。 The user can then modify the data, hit submit and the record updates (another script). 然后,用户可以修改数据,点击提交和更新记录(另一个脚本)。

Enabled errors. 启用的错误。 This is what is thrown: 这是抛出的内容:

Fatal error: Call to undefined method mysqli_result::fetch__assoc() in (path to script) on line 37 致命错误:在第37行(脚本路径)中调用未定义方法mysqli_result :: fetch__assoc()

Any ideas on what is wrong? 对什么地方有任何想法吗?

<?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?";
    }   
?>

You have a double underscore on fetch__assoc() , this should have only a single underscore: fetch_assoc() . 您在fetch__assoc()上有一个双下划线,这应该只有一个下划线: fetch_assoc() Specifically change this: 具体更改此:

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

To: 至:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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