簡體   English   中英

action.php 無法從數據庫表中獲取數據

[英]action.php could not fetch the data from the database table

所以我必須在從我的數據庫中獲取的表中顯示行。 我有一個 JQuery 來提取代碼,但它顯示了錯誤

解析錯誤:語法錯誤,意外的“;” 在 C:\\xampp\\htdocs\\hopeplace\\madmin\\action.php 第 49 行

<?php 
//action.php
if(isset($_POST["action"]))
{

include('../connect.php');

if($_POST["action"] == 'fetch')
{
    $output='';
    $query ="SELECT * FROM user_details WHERE user_type ='user' ORDER BY user_name ASC";
    $statement = $Conndb-> prepare($query);
    $statement->execute()
    $result = $statement->fetchAll();//line 14
    $output .= '

        <table class="table table-hover">
            <tr>    
                <td>Full Name</td>
                <td>Email</td>
                <td>Status</td>
                <td>Action</td>
            </tr>

            ';
    foreach($result as $row){
        $status ='';
        if($row["user_status"] == 'Active'){

            $status = '<span class="label label-success">Active</span>';
        }
        else{

            $status = '<span class="label label-danger">Inactive</span>';
        }

        $output .= '
        <tr>
            <td>'.$row["user_name"].'</td>
            <td>'.$row["user_email"].'</td>
            <td>'.$status.'</td>
            <td><button type="button" name ="action" class="btn btn-info btn-xs action" data-user_id="'.$row["user_id"].'" data-user_status="'.$row["user_status"].'">Action</button></td>
        </tr>
        ';
    }

    $output .= '</table'>;//line 49
    echo $output;

}
}
?>

即使我將代碼更改為

$output .= '</table>';//line 49

它告訴我另一個錯誤

致命錯誤:未捕獲的錯誤:調用 C:\\xampp\\htdocs\\hopeplace\\madmin\\action.php:14 中未定義的方法 mysqli_stmt::fetchAll() 堆棧跟蹤:#0 {main} throw in C:\\xampp\\htdocs\\ Hopeplace\\madmin\\action.php 在第 14 行

從行:

$statement->execute()

看起來您忘記用分號終止它。

它應該是:

$statement->execute();

fetchAll()用於PDO

fetch_all()用於MySQLi ,這似乎是您正在使用的。

你混淆了 PDO 和 mysqli。 嘗試下面的代碼替換,它與 mysqli 相同。 $輸出='';

$stmt = $this->db->prepare($query);
$stmt->execute();

//grab a result set
$resultSet = $stmt->get_result();

//pull all results as an associative array
$result = $resultSet->fetch_all();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM