我正在爲條形碼票務系統構建一個驗證器腳本。需要根據數據庫檢查條形碼號碼。事情是條形碼的前7個數字是客戶ID,最後4個數字是座位ID。來自1個輸入的2個值,MySQL MySQL
例如:
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'];
}
?>
感謝您的幫助。
你的問題是什麼?另外,$ hash是如何計算的? – cernunnos 2013-04-05 16:44:21
您的代碼仍然容易受到SQL注入的影響。瞭解準備好的陳述。 – Kermit 2013-04-05 16:45:07
@cernunnos顯然的問題是如何? – mplungjan 2013-04-05 16:46:51