dongxunhua2054 2018-02-03 05:34
浏览 37
已采纳

我的checkbooking.php上的未定义索引

This is the error I have: This is the error i have

Below is my php booking page . I have trouble solving the error. I faced in check booking page below. I can't find the undefined index error for service, eventdate, Customer ID. Can you help me?

   <?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>

this is my checkbook php page .Its shows undefined index error for 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");
    }
    ?>  
  • 写回答

1条回答 默认 最新

  • doutuo3935 2018-02-03 05:56
    关注

    you need to check your variable like that

    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");
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法