【发布时间】:2013-03-28 04:18:07
【问题描述】:
我正在为条形码票务系统构建验证器脚本。需要根据数据库检查条形码编号。问题是条形码的前 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'];
}
?>
感谢您的所有帮助。
【问题讨论】:
-
您的问题是什么?还有,$hash 是怎么计算的?
-
您的代码仍然容易受到 SQL 注入的攻击。了解准备好的语句。
-
@cernunnos 显然问题是如何?
-
我只是想知道如何将输入分成 2 个值并发布到 php 文件中。
-
使用substring。
标签: php jquery mysql post input