2017-08-30 86 views
-1

無論我嘗試什麼,我都已經搜索過這個並且不斷收到錯誤。顯示某些記錄的結果

主要的錯誤,我得到的是:

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> 
+0

在['mysqli_fetch_assoc()'](http://php.net/manual/en/的文檔看看mysqli的-result.fetch-assoc.php)。它需要一個類型['mysqli_result()'](http://php.net/manual/en/class.mysqli-result.php)的參數,它是通過調用['mysqli_query()'](http ://php.net/manual/en/mysqli.query.php)。 – axiac

回答

0

你需要把$result=mysqli_query($con,$sql);首先,你可以使用

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