2016-12-17 23 views
0

我已經創建了這3頁的表格。第一是註冊,第二是入境和出境日期,現在是第三次,我想讓用戶在價值停車,迎接和迎接服務停車和靈活的停車場之間進行選擇。我在他們每個人旁邊創建了一個「選擇」按鈕,但是,當我點擊按鈕時,我檢查了我的數據庫,並且只有id和用戶名得到更新,停車名不會出現..這裏是我的代碼:PHP:程序無法運行。我不明白錯誤

<?php 
session_start(); 
$error=true; 
$users=$_SESSION['tsmUserName']; 
$Parkingname=""; 
if (isset($_POST['tsmValueaParking'])){ 
    $name="value Parking"; 
    $error=false; 
} 
if (isset($_POST['tsmMeetGreetService'])){ 
    $name="Meet and Greet Service Parking"; 
$error=false; 
} 
if (isset($_POST['tsmFlexible'])){ 
    $name="Flexible Parking"; 
    $error=false; 
} 
if($error==false){ 
    require_once("connection.php"); 
      $my_query="INSERT INTO `parking`(`Id`, `name`, `username`) VALUES (NULL,'$name','$users')"; 
      $result=mysqli_query($connection,$my_query); 
      if($result) 
      { 
       echo 'thank you'; 
      } 
      else 
      { 
       echo 'error'; 
      } 
      mysqli_close($connection); 
} 

?> 
<html> 
<head></head> 
<body> 
<form name="picking" id="picking" method="POST" action=""> 
<table cellpadding="5" border="0" width="100%"> 
<tr> 
      <td align="center"> 
       <h2> Welcome to Tassimo Online Supermarket </h2> 
       <hr> 
      </td> 
     </tr> 
     <tr> 
     <td width="30%" align="left"> 
        <label for="tsmdate">Value Parking</label></br></br> 
        Our car park is the closest off car park to both terminals. FREE shuttle bus runs every 10 minutes and gets you to the terminals in 3-5 minutes. 
       </td> 
       </tr> 
       <tr> 
       <td align="left"> 
        <input type="button" name="tsmValueaParking" id="tsmValueaParking" value="pick"> 
       </td> 

       </tr> 

       <tr> 
       <td width="30%" align="left"> 
        <label for="tsmdate">Meet & Greet Service</label></br></br> 
        This is a Meet and Greet Service where you will be met at your departure terminal. Your car will be parked at the secure facility. With this service staff member will meet you at your departure terminal and take your car back to their secure compound. On your return staff member will meet you at the Terminal with your car so you can be on your way home as quickly as possible. 
       </td> 
       </tr> 
      <tr> 
       <td align="left"> 
        <input type="button" name="tsmMeetGreetService" id="tsmMeetGreetService" value="pick"> 
       </td> 
       </tr> 

       <tr> 
       <td width="30%" align="left"> 
        <label for="tsmdate">Flexible</label></br></br> 
        This car park is located just 500 meters away. The bus service runs every 30 mins. Tickets cost $4.50 one way and are available from the driver. 
       </td> 
       </tr> 
       <tr> 
       <td align="left"> 
        <input type="button" name="tsmFlexible" id="tsmFlexible" value="pick"> 
       </td> 

       </tr> 
      </table> 


</form> 
+0

在你的''Parkingname =「」;'在最上面的行中加入'$ name ='test';'看看它是否添加到數據庫中。此外,請執行'print_r($ _ POST);'看看您提交的內容是否符合您的期望。 – Rasclatt

+0

@Rasclatt我試過var_dump,但它無法識別$ _POST,因爲數組顯示爲0 ..我該怎麼做:/我很困惑 –

+0

將所有' Rasclatt

回答

0

該問題可能是由於您的表單由於字段類型而未正確提交。將所有您:

<input type="button" 

<input type="submit" 

然後嘗試並再次提交。我認爲如果切換類型提交您將看到您的$_POST正常工作。

在附註中,如果您有用戶提交的數據,則需要確保仔細綁定參數。你想避免sql注入。