我正在尝试从数据库表中获取一些简单的信息并将其发布在 HTML 页面上。这看起来非常简单直接,我没有收到任何错误,这意味着我连接到数据库和表。我已经拥有所有数据(手动输入)。
我假设这是我调用列名进行查询的方式。
<?php
require_once("settings.php");
//Open Connection
$conn = @mysqli_connect("$host","$user","$pswd")
or die ('Failed To Connect to Server');
@mysqli_select_db("$conn", "$dbnm")
or die ('Database Not Available');
//Set up SQL string and excecute
$car_id = mysqli_escape_string($_GET['car_id']);
$make = mysqli_escape_string($_GET['make']);
$model = mysqli_escape_string($_GET['model']);
$price = mysqli_escape_string($_GET['price']);
$query = "SELECT car_id, make, model, price FROM cars";
$results = mysqli_query($conn, $query);
echo "<table width ='100%' border='1'>
<tr>
<th>car_id</th>
<th>make</th>
<th>model</th>
<th>price</th>
</tr>";
// $row = mysqli_fetch_row($query);
while ($row = mysqli_fetch_array($results)) {
echo "<tr>";
echo "<td>" . $row['car_id'] . "</td>";
echo "<td>" . $row['make'] . "</td>";
echo "<td>" . $row['model'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "</tr>";
// $row = mysqli_fetch_row($query);
}
echo "</table>";
//Close Connection
mysqli_free_result($results);
mysqli_close($conn);
?>
settings.php 保存了所有的连接信息,并且全部都签出。我什至需要 ($_GET['car_id']) 等吗?我可以通过字段名称来称呼他们吗?
答案会很明显...