以下是我的php预订页面。我无法解决错误。我面对下面的支票预订页面。我找不到service,eventdate,Customer ID的未定义索引错误。你能救我吗?
<?php
session_start();
if(!isset($_SESSION['MM_Username']))
{
header("Location:login.php");
}
$un = $_SESSION["MM_Username"];
$conn = mysqli_connect("localhost", "root", "" , "m3_162931g_db");
$sql = "SELECT * from customer where Username='$un'";
$user = mysqli_query($conn, $sql);
$oneUser = mysqli_fetch_assoc($user);
?>
<content>
<h1>Booking Page</h1>
<form action="checkbook.php" method="post" style="border:1px solid #ccc">
<div class="container">
<label><b>Services :</b></label>
<select name ="service" placeholder="Select Service">
<option value="1" >Wedding</option>
<option value="2" >Same Day Printing</option>
<option value="3" >Instagram Images</option>
<option value="4" >Family Photo</option>
<option value="5" >Green Screen Photography</option>
<option value="6" >Corporate Event</option>
<option value="7" >Business Portrait</option>
<option value="8" >Advertisment Printing</option>
<option value="9" >Award Ceremonies</option>
</select>
<br>
<label><b>Date :</b></label>
<input type="date" name="eventdate" required>
<input type="text" id="hide" name="CustomerID" value="<?php echo
$oneUser['CustomerID']; ?>" hidden="hidden" >
<div class="clearfix">
<button type="reset" class="cancelbtn">Cancel</button>
<button type="submit" class="signupbtn">Book</button>
</div>
</div>
</form>
这是我的支票簿php页面。它显示了service,eventdate,customerID
的未定义索引错误 <?php
session_start();
$service = $_POST['service'];
$eventdate = $_POST['eventdate'];
$customerID = $_POST['CustomerID'];
$bs = "B";
$conn = mysqli_connect("localhost", "root", "" , "m3_162931G_db");
$sql = "insert into booking(ProductID,CustomerID,Booking_Date,status)
values ('$service','$customerID','$eventdate', '$bs')";
$result = mysqli_query($conn,$sql);
if ($result){
header("Location:orderhistory.php");
}
?>
答案 0 :(得分:1)
你需要像那样检查你的变量
if (isset($_POST['service'])) {
$service = $_POST['service'];
$eventdate = $_POST['eventdate'];
$customerID = $_POST['CustomerID'];
$bs = "B";
$conn = mysqli_connect("localhost", "root", "" , "m3_162931G_db");
$sql = "insert into booking(ProductID,CustomerID,Booking_Date,status)
values ('$service','$customerID','$eventdate', '$bs')";
$result = mysqli_query($conn,$sql);
if ($result){
header("Location:orderhistory.php");
}
}