我无法检查我的凭证到数据库。我认为我的$ VouchExist的sql查询是错误的,我已经尝试了一切。我有正确的语法吗?我想检查用户输入的凭证是否存在于数据库中。我在数据库中有多张优惠券。
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
sec_session_start();
if (login_check($mysqli) == true) {
$logged = 'accessing';
} else {
$logged = 'not accessing';
}
$username = $_SESSION['username'];
$getemail = mysqli_query($mysqli, "SELECT email FROM members WHERE username = '$username' ");
$email = '';
while($gear = mysqli_fetch_array( $getemail )) {
$email = $gear['email'];
}
$userVouch = $_POST['vouchercheck'];
echo $userVouch;
$VouchExist = mysqli_query($mysqli, "SELECT voucher FROM vouchers WHERE voucher = '$userVouch' ");
if(isset($_POST['seatme'])){
if(!empty($_POST['flight'])){
foreach($_POST['flight'] as $key=>$selected){
echo "<p>You have selected seat: ".$selected."</p>";
}
}
}
if (empty($VouchExist))
{
print 'BUT there is no voucher, Please Enter a voucher.<br>';
}
else {
$var = 1;
if ( $result = mysqli_query($mysqli, "INSERT INTO seating (flight_id, email, seat_id) VALUES ('$var', '$email', '$selected')"))
{
echo "<font color='green'>Successfully taken seat.<br>";
echo "<br/><a href='user.php'>Back to seating</a>";
}
else{
print 'something wrong here<br>';
}
}
?>
这是连接优惠券的user.php
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
ini_set('display_errors',"1");
sec_session_start();
?>
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Secure Login: Plane Create</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/user.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="index.php">Airways</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="index.php">Home
<span class="sr-only">(current)</span>
</a>
</li>
<?php if (login_check($mysqli) == true && $_SESSION['username'] == "admin"):?>
<li class="nav-item">
<a class="nav-link" href="protected_page.php">Plane Control</a>
</li>
<?php elseif (login_check($mysqli) == true && $_SESSION['username'] != "admin") : ?>
<li class="nav-item">
<a class="nav-link" href="user.php">Plane</a>
</li>
<?php else: ?>
<li class="nav-item">
<a class="nav-link" href="register.php">Plane</a>
</li>
<?php endif; ?>
<li class="nav-item">
<a class="nav-link" href="#">Account</a>
</li>
<li class="nav-item">
<a class="nav-link" href="register.php">Login</a>
</li>
</ul>
</div>
</div>
</nav>
<?php if (login_check($mysqli) == true && $_SESSION['username'] == "admin"):?>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-3">
<h1 class="my-4">Admin Panel</h1>
<div class="list-group">
<div class="btn-group-horizontal ">
<a href="protected_page.php" class="btn btn-Primary" role="button">Admin Page</a><br>
<a href="user.php" class="btn btn-Primary" role="button">User Page</a><br>
<a href="index.php" class="btn btn-Primary" role="button">HomePage</a><br>
</div>
</div>
</div>
<?php elseif (login_check($mysqli) == true && $_SESSION['username'] != "admin") : ?>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-3">
<h1 class="my-4">User Panel</h1>
<div class="list-group">
<a href="user.php" class="btn btn-Primary" role="button">User Page</a><br>
<a href="index.php" class="btn btn-Primary" role="button">HomePage</a><br>
</div>
</div>
<!-- /.col-lg-3 -->
<?php else: ?>
<p>
<span class="error">You are not authorized to access this page.</span> Please <a href="index.php">login</a>.
</p>
<?php endif; ?>
<?php if (login_check($mysqli) == true) : ?>
<div class="col-lg-9">
<div class="card mt-4">
<div class="card-body">
<h3 class="card-title" style="text-align: center;">Select your seats and flights below</h3>
<h4>Steps:</h4>
<p class="card-text">
<p>Welcome <?php echo htmlentities($_SESSION['username']); ?>!</p>
<p>
-First scroll below and select you flight,<br>
-Then select which seats,<br>
-Then press submit<br>
</p>
<p>Return to <a href="index.php">homepage</a></p>
</p>
</div>
</div>
<!-- /.card -->
<div class="card card-outline-secondary my-4 text-center">
<div class="card-header">
Order a seat ticket
</div>
<div class="plane">
<div class="cockpit" >
<h1>Please select a seat</h1>
</div>
<div class="exit exit--front fuselage text-center">
</div>
<form action="flightselect.php" method="post" name="form">
<td>Please Enter Voucher</td>
<td><input type="text" name="vouchercheck"></td>
<ol class="cabin fuselage">
<li class="row row--1" style="padding-right: 100%;">
<ol class="seats" type="A" ">
<li class="seat">
<input type="radio" name="flight[]" id="1A" value="1A" />
<label for="1A">1A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="1B" value="1B" />
<label for="1B">1B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="1C" value="1C" />
<label for="1C">1C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="1D" value="1D" />
<label for="1D">1D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="1E" value="1E" />
<label for="1E">1E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="1F" value="1F" />
<label for="1F">1F</label>
</li>
</ol>
</li>
<li class="row row--2" style="padding-right: 100%;">
<ol class="seats" type="A">
<li class="seat">
<input type="radio" name="flight[]" id="2A" value="2A" />
<label for="2A">2A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="2B" value="2B" />
<label for="2B">2B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="2C" value="2C" />
<label for="2C">2C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="2D" value="2D" />
<label for="2D">2D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="2E" value="2E" />
<label for="2E">2E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="2F" value="2F" />
<label for="2F">2F</label>
</li>
</ol>
</li>
<li class="row row--3" style="padding-right: 100%;">
<ol class="seats" type="A">
<li class="seat">
<input type="radio" name="flight[]" id="3A" value="3A" />
<label for="3A">3A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="3B" value="3B" />
<label for="3B">3B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="3C" value="3C" />
<label for="3C">3C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="3D" value="3D" />
<label for="3D">3D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="3E" value="3E" />
<label for="3E">3E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="3F" value="3F" />
<label for="3F">3F</label>
</li>
</ol>
</li>
<li class="row row--4" style="padding-right: 100%;">
<ol class="seats" type="A">
<li class="seat">
<input type="radio" name="flight[]" id="4A" value="4A" />
<label for="4A">4A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="4B" value="4B" />
<label for="4B">4B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="4C" value="4C" />
<label for="4C">4C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="4D" value="4D" />
<label for="4D">4D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="4E" value="4E" />
<label for="4E">4E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="4F" value="4F" />
<label for="4F">4F</label>
</li>
</ol>
</li>
<li class="row row--5" style="padding-right: 100%;">
<ol class="seats" type="A">
<li class="seat">
<input type="radio" name="flight[]" id="5A" value="5A" />
<label for="5A">5A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="5B" value="5B" />
<label for="5B">5B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="5C" value="5C" />
<label for="5C">5C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="5D" value="5D" />
<label for="5D">5D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="5E" value="5E" />
<label for="5E">5E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="5F" value="5F" />
<label for="5F">5F</label>
</li>
</ol>
</li>
<li class="row row--6" style="padding-right: 100%;">
<ol class="seats" type="A">
<li class="seat">
<input type="radio" name="flight[]" id="6A" value="6A" />
<label for="6A">6A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="6B" value="6B" />
<label for="6B">6B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="6C" value="6C" />
<label for="6C">6C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="6D" value="6D" />
<label for="6D">6D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="6E" value="6E" />
<label for="6E">6E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="6F" value="6F" />
<label for="6F">6F</label>
</li>
</ol>
</li>
<li class="row row--7" style="padding-right: 100%;">
<ol class="seats" type="A">
<li class="seat">
<input type="radio" name="flight[]" id="7A" value="7A" />
<label for="7A">7A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="7B" value="7B" />
<label for="7B">7B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="7C" value="7C" />
<label for="7C">7C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="7D" value="7D" />
<label for="7D">7D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="7E" value="7E" />
<label for="7E">7E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="7F" value="7F" />
<label for="7F">7F</label>
</li>
</ol>
</li>
<li class="row row--8" style="padding-right: 100%;">
<ol class="seats" type="A">
<li class="seat">
<input type="radio" name="flight[]" id="8A" value="8A" />
<label for="8A">8A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="8B" value="8B" />
<label for="8B">8B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="8C" value="8C" />
<label for="8C">8C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="8D" value="8D" />
<label for="8D">8D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="8E" value="8E" />
<label for="8E">8E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="8F" value="8F" />
<label for="8F">8F</label>
</li>
</ol>
</li>
<li class="row row--9" style="padding-right: 100%;">
<ol class="seats" type="A">
<li class="seat">
<input type="radio" name="flight[]" id="9A" value="9A" />
<label for="9A">9A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="9B" value="9B" />
<label for="9B">9B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="9C" value="9C" />
<label for="9C">9C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="9D" value="9D" />
<label for="9D">9D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="9E" value="9E" />
<label for="9E">9E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="9F" value="9F" />
<label for="9F">9F</label>
</li>
</ol>
</li>
<li class="row row--10" style="padding-right: 4%";>
<ol class="seats" type="A">
<li class="seat">
<input type="radio" name="flight[]" id="10A" value="10A" />
<label for="10A">10A</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="10B" value="10B" />
<label for="10B">10B</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="10C" value="10C" />
<label for="10C">10C</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="10D" value="10D" />
<label for="10D">10D</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="10E" value="10E" />
<label for="10E">10E</label>
</li>
<li class="seat">
<input type="radio" name="flight[]" id="10F" value="10F" />
<label for="10F">10F</label>
</li>
</ol>
</li>
</ol>
<div class="exit exit--back fuselage">
</div>
</div>
<input type="submit" name="seatme" value="Submit" style="font-weight: bold;">
</form>
</div>
<!-- /.card -->
</div>
<!-- /.col-lg-9 -->
</div>
</div>
<!-- /.container -->
</body>
<!-- Footer -->
<footer class="py-5 bg-dark">
<div class="container">
<p class="m-0 text-center text-white">Copyright © Matthew, Stephen, Nick</p>
</div>
<!-- /.container -->
</footer>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<?php else : ?>
<p>
<span class="error">You are not authorized to access this page.</span> Please <a href="index.php">login</a>.
</p>
<?php endif; ?>
</html>
答案 0 :(得分:0)
要获得准确答案,我需要更多详细信息,例如表格结构/样本数据。但目前,您可以更好地更改查询,如下所示
$currentUser
或者您可以通过回显查询来调试查询,如下所示
{{ currentUser }}
希望这可以解决您的问题。欢迎您提出任何进一步的意见