首先,我需要创建一个表单,允许用户输入起始邮政编码和结尾邮政编码,并在该范围内的所有邮政编码之间输出记录列表。它们也必须按姓氏排序。到目前为止,这就是我所拥有的。它可以工作,如果我从我的插入文件发送值到我的客户文件,但客户文件本身有一个错误,我无法弄清楚。我也无法弄清楚如何按姓氏对它们进行排序。
http://erobi022.pairserver.com/ZipRecord.php
<!DOCTYPE html>
<html>
<body>
Find all customers between these two ranges.
<form action="Customers.php" method="get">
Beginning Zip:
<input type="text" name="Zip1">
Ending Zip:
<input type="text" name="Zip2">
<button type="sumbit">Find</button>
</form>
</body>
</html>
邮政编码在此处发送。他们应该使用该范围之间的邮政编码检索和发布客户,并按姓氏对其进行排序。此文件本身也不起作用并显示错误。
SELECT userID, FirstName, LastName, Address1, City, State, Zip FROM Customers WHERE Zip > AND Zip < ;No records returned:
您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在&#39; AND Zip&lt;&#39;在第1行
http://erobi022.pairserver.com/Customers.php
<?php
//page 368 in text, but i prefer w3schools method, Select Data with MySQLi
require("readonly.php");
$sql = "SELECT userID, FirstName, LastName, Address1, City, State, Zip"; //dont use * to show all columns
$sql .= " FROM Customers";
//$Zip1=$_GET["Zip1"];
//$Zip2=$_GET["Zip2"];
$sql .= " WHERE Zip > ";
//$sql .= mysqli_real_escape_string($conn, $Zip1);
$sql .= mysqli_real_escape_string($conn, $_GET["Zip1"]);
$sql .= " AND Zip < ";
//$sql .= mysqli_real_escape_string($conn, $Zip2);
$sql .= mysqli_real_escape_string($conn, $_GET["Zip2"]);
//$sql .= "ORDER By LastName";
//$sql .= mysqli_real_escape_string($conn, $_GET["LastName"]);
$sql .=";";
echo "</p>" . $sql;
$result = $conn->query($sql); //$result is a dataset
if (!$result) {
echo "No records returned: </p> " . mysqli_error($conn);
} else {
echo "Query successful.";
if ($result->num_rows > 0 ) { //if there are rows in the dataset...
//output data of each rows
while($row = $result->fetch_assoc()) {
echo "<form action='delete.php' method='post'>";
echo "userID"; //you could use a table format or CSS
// dont forget htmlentities before outputting to screen!
echo htmlentities($row["userID"]);
echo "</br>FirstName: ";
echo htmlentities($row["FirstName"]);
echo "</br>LastName: ";
echo htmlentities($row["LastName"]);
echo "</br>Address: ";
echo htmlentities($row["Address1"]);
echo "</br>City: ";
echo htmlentities($row["City"]);
echo "</br>State: ";
echo htmlentities($row["State"]);
echo "</br>Zip: ";
echo htmlentities($row["Zip"]);
echo "<input type='text' name='userID' value='";
echo htmlentities($row["userID"]) ."'>";
echo "<button type='Submit'>Delete</button>";
echo "</form>";
echo "</p>";
}
} else {
echo "No results returned";
}
}
$conn->close(); //this is not necessary because connection closes automatically
?>
有人能发现错误吗?