我收到了这个错误:
(!)致命错误:在第427行的C:\ wamp64 \ www \ 01 \ Script \ u07 \ user \ Campaigns.php中调用null上的成员函数rowCount()
我正在使用此代码。谁能指出我在哪里错了?
<?php
$db_host = 'localhost'; // Server Name
$db_user = 'root'; // Username
$db_pass = 'PAss'; // Password
$db_name = 'DB name'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = "SELECT name,name2,estado,userId,id FROM links WHERE userId ='" .
$_SESSION["user"] . "'";
$query = mysqli_query($conn, $sql);
if($stmt->rowCount() > 0) {
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
if (!$query) {
die('SQL Error: ' . mysqli_error($conn));
}
?>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<table class="table table-hover table-bordered"
id="sampleTable">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($query)) {
$amount = $row['amount'] == 0 ? '' : number_format($row['amount']);
echo '<tr>
<td>' . $row['id'] . '</td>
<td>' . $row['name'] . '</td>
<td>0/' . $row['name2'] . '</td>
<td><span class="label label-success">' . $row['estado'] .
'</span></td>
<td><a class="btn btn-sm btn-danger" id="delete_product"
data-id="<?php echo $id; ?>" href="javascript:void(0)"><i
class="glyphicon glyphicon-trash"></i></a>
<a class="btn btn-sm btn-danger" id="delete_product" data-
id="' . $row['id'] . '" href="javascript:void(0)"><i
class="glyphicon glyphicon-trash"></i></a>
<td><a class="btn btn-sm btn-danger" id="delete_product"
data-id="<?php echo $id; ?>" href="javascript:void(0)"><i
class="fa fa-trash-o"></i></a></td>
</td>
</tr>';
}
?>
<?php
}
} else {
?>
<tr>
<td colspan="3">No Products Found</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
$stmt
似乎未在您的代码中定义。