2012-03-16 79 views
-1

我在PHP中提交一個註冊表單,當提交表單Date(Check In,我已經使用Date Picker)時,組合框(性別&房間號)&複選框(出租車)未插入。日期選擇器和組合框的值不會去mysql

我已經看了足夠的代碼,但沒有得到什麼錯誤..雖然其他組合框和複選框工作得很好。

PHP代碼 -

<?php 

$passport = $_POST['passport']; 
$name = $_POST['name']; 
$sex = $_POST['sex']; 
$address1 = $_POST['address1']; 
$address2 = $_POST['address2']; 
$city = $_POST['city']; 
$country = $_POST['country']; 
$contact = $_POST['contact']; 
$email = $_POST['email']; 
$roomNo = $_POST['roomNo']; 
if(isset($_POST['food']) && $_POST['food'] == 'food') 
{ 
    $food = 'yes'; 
} 
else 
{ 
    $food = 'no'; 
} 
if(isset($_POST['car']) && $_POST['car'] == 'car') 
{ 
    $car = 'yes'; 
} 
else 
{ 
    $car = 'no'; 
} 
if(isset($_POST['others']) && $_POST['others'] == 'others') 
{ 
    $others = 'yes'; 
} 
else 
{ 
    $others = 'no'; 
} 
$checkIn = $_POST['checkIn']; 


mysql_connect("localhost","root",""); 
mysql_select_db("guesthouse"); 

$personal_query = "INSERT INTO personal_details VALUES(
                 '', 
                 '$name', 
                 '$sex', 
                 '$address1', 
                 '$address2', 
                 '$city', 
                 '$country', 
                 '$contact', 
                 '$email')"; 
mysql_query($personal_query); 
$result = mysql_affected_rows(); 

if($result == 1) 
{ 
    echo "Personal Details Submitted"; 
} 

$booking_query = "INSERT INTO booking VALUES(
               '', 
               '$name', 
               '$roomno', 
               '$food', 
               '$taxi', 
               '$others', 
               '$checkIn')"; 

mysql_query($booking_query); 
$result = mysql_affected_rows(); 

if($result == 1) { 
    echo "<br/>Booking Details Submitted"; 
}  
?> 

HTML -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" /> 
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script> 
<script type="text/javascript"> 
    window.onload = function(){ 
     new JsDatePick({ 
      useMode:2, 
      target:"checkIn", 
      dateFormat:"%d-%M-%Y" 
      /*selectedDate:{     
       day:5,     
       month:9, 
       year:2006 
      }, 
      yearsRange:[1978,2020], 
      limitToToday:false, 
      cellColorScheme:"beige", 
      dateFormat:"%m-%d-%Y", 
      imgPath:"img/", 
      weekStartDay:1*/ 
     }); 
    }; 
</script> 
</head> 
<form name="form1" method="post" action="registration_handle.php"> 
    <table width="60%" border="0" align="center" cellpadding="0" cellspacing="0"> 
    <tr> 
     <td colspan="2" align="center" bgcolor="#0099FF">Room Reservation Details :</td> 
    </tr> 
    <tr> 
     <td width="33%" align="center" bgcolor="#66FFCC">Passport No </td> 
     <td width="67%"><label for="textfield"></label> 
     <input type="text" name="passport" id="passport"></td> 
    </tr> 
    <tr> 
     <td align="center" bgcolor="#66FFCC">Name</td> 
     <td><input type="text" name="name" id="name"></td> 
    </tr> 
    <tr> 
     <td align="center" bgcolor="#66FFCC">Sex</td> 
     <td><label for="select3"></label> 
     <select name="sex" id="sex"> 
     <option value="" selected>Male</option> 
     <option value="" >Female</option> 
     </select></td> 
    </tr> 

    <tr> 
     <td align="center" bgcolor="#66FFCC">Address 1</td> 
     <td><input type="text" name="address1" id="address1"></td> 
    </tr> 
    <tr> 
     <td align="center" bgcolor="#66FFCC">Address2</td> 
     <td><input type="text" name="address2" id="address2"></td> 
    </tr> 
    <tr> 
     <td align="center" bgcolor="#66FFCC">City</td> 
     <td><input type="text" name="city" id="city" /></td> 
    </tr> 
    <tr> 
     <td align="center" bgcolor="#66FFCC">Country</td> 
     <td><label for="select2"></label> 
     <select name="country" id="country"> 
     <?php 
      mysql_connect("localhost","root",""); 
      mysql_select_db("guesthouse"); 

      $query = "SELECT name FROM country"; 
      $query_result = mysql_query($query); 
      while($result = mysql_fetch_assoc($query_result)) 
      { 
      ?> 
       <option value = "<?php echo $result['name'] ?>"><?php echo $result['name'] ?></option> 
      <?php 
      }  
     ?> 
     </select></td> 
    </tr> 

    <tr> 
     <td align="center" bgcolor="#66FFCC">Contact No</td> 
     <td><input type="text" name="contact" id="contact"></td> 
    </tr> 
    <tr> 
     <td align="center" bgcolor="#66FFCC">E-Mail </td> 
     <td><input type="text" name="email" id="email"></td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td align="center" bgcolor="#66FFCC">Room No</td> 
     <td><label for="select4"></label> 
     <select name="roomNo" id="roomNo"> 
     <?php 
      mysql_connect("localhost","root",""); 
      mysql_select_db("guesthouse"); 

      $query = "SELECT name FROM roomno"; 
      $query_result = mysql_query($query); 
      while($result = mysql_fetch_assoc($query_result)) 
      { 
      ?> 
       <option value = "<?php echo $result['name'] ?>"><?php echo $result['name'] ?></option> 
      <?php 
      }  
     ?> 
     </select></td> 
    </tr> 
    <tr> 
     <td align="center" bgcolor="#66FFCC">Extra Service</td> 
     <td><p> 
     <label>  </label> 
     <input type="checkbox" name="food" value="food" />Food 
     <input type="checkbox" name="car" value="car" />Car 
     <input type="checkbox" name="others" value="others" />Others<br> 
     </p></td> 
    </tr> 
    <tr> 
     <td align="center" bgcolor="#66FFCC">Check In </td> 
     <td><label for="textfield3"></label> 
     <input type="text" size="16" name="checkIn" id="checkIn"></td> 
    </tr> 

    <tr> 
     <td>&nbsp;</td> 
     <td><input type="submit" name="button" id="button" value="Submit"> 
     <input type="reset" name="Reset" id="Reset" value="Reset" /> 
     <input type="submit" name="cancel" id="cancel" value="Cancel" /></td> 
    </tr> 
    </table> 
</form> 

</html> 
+0

你需要指定你的插入字段/行去檢查INSERT:http:// dev .mysql.com/doc/refman/5.0/en/insert.html – 2012-03-16 19:22:31

+0

當我們爲任何表發送每個值時,我們不需要描述表的字段名稱。 其他字段值正在插入,但只有一些給定的字段值爲NULL – 2012-03-16 19:30:26

+0

您可以發佈HTML嗎? – j08691 2012-03-16 19:35:31

回答

0

sex""(如果你想默認情況下,不要輸入值= 「」) -Tested-

<html> 
<body> 

<select onchange="alert(this.value);"> 
    <option>Volvo</option> 
    <option>Saab</option> 
    <option value=''>Mercedes</option> 
    <option>Audi</option> 
</select> 

</body> 
</html> 

你永遠不會給$taxi(至極在您的形式叫car

您initialte $roomNo和存儲$roomno

---發現這些錯誤,因爲我傾向於做同樣的事情。這裏有一個提示,總是首先驗證你的變量名稱,你的probs的99%將被修復---(適用於我:))

+0

是的,這些問題已被刪除。 可以請你幫我插入日期值,因爲我知道我將不得不改變格式,但不知道該怎麼辦.. 感謝您的幫助:) – 2012-03-20 12:31:35

+0

我個人使用時間戳 - 他們很容易與幾乎所有的東西一起工作和兼容。否則你可能想檢查mysql的日期格式。 – 2012-03-20 14:12:04