<分区>
我正在尝试将数据库中的值显示到网页上。这是下面的代码。
//connect db
$dbc = mysqli_connect('localhost', 'root', '', 'mylearndb') OR die('Cannot connect because: '.mysqli_connect_error());
//Run query...
$q = "SELECT * FROM 'pages' WHERE id = 1";
$r = mysqli_query($dbc, $q);
$page = mysqli_fetch_assoc($r);
在索引页中,我尝试将结果打印在表格中:
<table>
<tr>
<td>Customer ID</td>
<td>Full Name</td>
<td>Email ID</td>
<td>Phone no</td>
</tr>
<tr>
<td><?php echo $page['cust_id']; ?></td>
<td><?php echo $page['full_name']; ?></td>
<td><?php echo $page['email_id']; ?></td>
<td><?php echo $page['phone_no']; ?></td>
</tr>
</table>
当我检查页面时,它抛出错误...
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in..
上面的代码在一个名为 setup.php
的文件中运行,我将该文件调用到 index.php
中。