【问题标题】:Show results from certain record显示特定记录的结果
【发布时间】:2018-02-07 14:58:48
【问题描述】:

我已经搜索过这个并且无论我尝试什么都会不断出错。

我得到的主要错误是:

mysqli_fetch_assoc() 期望参数 1 是 mysqli_result,给定字符串

我创建了一个显示所有记录的页面。然后,用户选择一条记录进行编辑,并将 id 传递到此页面,该页面将显示表单/表格中的所有字段。一些字段是只读的,因此无法修改。 我想要实现的是在表格中显示结果,以便可以对其进行编辑,然后将其发送到数据库并进行更新。我正在考虑将其发送到另一个文件进行更新,然后将它们发送回查看结果页面。

<form action = 'modify2.php' method = 'post'>
    <table border="1">  
    <tr style="border-bottom:1px solid #000000;">
    <strong>User ID</strong>
    <strong>Username</strong>
    <strong>Password</strong>
    <strong>Email</strong>
    <strong>Name</strong>
    <strong>Submitted By</strong>
    <strong>Memeber Since</strong>
    </tr>

    <?PHP
    //error check to see what results are obtained
    echo '<br />sql code = '.$sql.'<br/>'; // this works bot the $result 
    shows nothing
    //die();

    //fetch object array and put into a row
    //while($row = mysqli_fetch_assoc($result))
    while($row = mysqli_fetch_assoc($sql))  
    { 
        ?>
        <tr><td><label>User ID :</label></td>
        <td><input type = 'text' name = 'id' id = 'id' value='<?PHP echo $row["id"];?>' readonly/></input><br /></td></tr>
        <tr><td><strong>Username</strong></td>
        <td><input type = 'text' name = 'username' id = 'username' value='<?PHP echo $row["username"];?>'/></input><br /></td></tr>
        <tr><td><label>password :</label></td>
        <td><input type = 'text' name = 'password' id = 'password' value='<?PHP echo $row["password"];?>'/></input><br /></td></tr>
        <tr><td><label>email :</label></td>
        <td><input type = 'text' name = 'email' id = 'email' value='<?PHP echo $row["email"];?>'/></input><br /></td></tr>
        <tr><td><label>Real Name :</label></td>
        <td><input type = 'text' name = 'Name' id = 'Name' value='<?PHP echo $row["Name"];?>'/></input><br /></td></tr>
        <tr><td><label>submitted by :</label></td>
        <td><input type = 'text' name = 'submittedby' id = 'submittedby' value='<?PHP echo $row["submittedby"];?>' readonly/></input><br /></td></tr>
        <tr><td><label>trn_date :</label></td>
        <td><input type = 'text' name = 'trn_date' id = 'trn_date' value='<?PHP echo $row["trn_date"];?>' readonly/></input></td></tr>
        <?PHP
     } 
    //close table here
    ?>
    <tr><td colspan='2'><div align='center'><input type = 'submit' value ='Modify Record' name = 'submit'/></td></tr>
    </form></div>
    </table>

【问题讨论】:

标签: php html forms mysqli html-table


【解决方案1】:

你需要把$result=mysqli_query($con,$sql);放在第一位才能使用

// Associative array
$row=mysqli_fetch_assoc($result);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 2012-10-24
    相关资源
    最近更新 更多