繁体   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