我正在为条形码票务系统构建验证器脚本。需要根据数据库检查条形码编号。问题是条形码的前 7 个数字是客户 ID,后 4 个数字是座位 ID。
例如:
12345671234
^^^^^^^--Customer ID
^^^^-- Seat ID
由于我将使用条码扫描仪扫描条码并将整个条码写入单个输入框中,因此我需要在该 1 个输入中分离这两个值,以便从数据库中获取正确的数据。
它现在像:
<form action="validator.php" method="post">
Customer ID: <input id="uuid" name="uuid" maxlength="7"><br>
Seat: <input id="hash" name="hash" maxlength="4">
需要像:
Barcode: <input id="barcode" name="barcode" maxlength="11"><input type="submit">
<input type="submit">
</form>
和 PHP 端
<?php
$uuid = $_POST['uuid'];
$hash = $_POST['hash'];
$con=mysqli_connect("localhost","admin","321","db_name");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM seat_booking_bookings
WHERE uuid ='$uuid'");
while($row = mysqli_fetch_array($result))
{
echo $row['customer_name'] . " " . $row['customer_phone'];
echo "<br>";
}
$result = mysqli_query($con,"SELECT * FROM seat_booking_bookings_seats
WHERE hash ='$hash'");
while($row = mysqli_fetch_array($result))
{
echo "Seat:";
echo $row['seat_id'] . " " . $row['price'];
}
?>
感谢你的帮助。