我收到一个错误,表示它是空的。 但是当我的文本字段为空时,它不会显示错误。我的意思是它允许空字段,但不能在选择的选项
中这是我的HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form role="form" id="cakechoices" name="cakechoices" method="post">
<label for="dedicationT"> Dedication Text: </label> <input type="text" name="dedicationT" id="dedicationT" size="20" placeholder="Dedication" />
<label for="service_date"> Date: </label> <input type="date" id="service_date" name="service_date" value="M-D-YY"/>
<br> <label> Branch: <select name="branch_name" id="branch_selection" />
<option disabled selected value>-- Select one --</option>
<option value="B1">B1 </option>
<option value="B2">B2 </option>
<option value="B3">B3 </option>
<option value="B4">B4 </option>
</select> </label>
</br>
<input type="submit" id="submit" class="btn btn-default" value="Order Now" />
</form>
这是我的php:
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) { die('Could not connect: ' . mysql_error()); }
if (!mysql_select_db('myrnas')) { die('Could not select database: ' . mysql_error()); }
session_start();
$dedicationT = $_POST['dedicationT'];
$service_date = $_POST['service_date'];
$branch_name = $_POST['branch_name'];
$query1 = "INSERT INTO order_cake (dedicationT, service_date, branch_name) VALUES ( '$dedicationT', '$service_date', '$branch_name');
if(@mysql_query($query1,$link))
{ echo "Done!"; }
else { print '<p> <h1> Somethings wrong, failed to connect!!!. GAD WHY!?! </h1> '.mysql_error().'</p>'; }
?>
这是我的错误: 未定义的索引: D:\ Xampp \ htdocs \ system \ customize \ ordersent.php 中的Branch_name 4
这是我在html文件中的Ajax相同
function submit_order($form) {
$.ajax({
url : "process/ordersent.php",
type : "POST",
cache : false,
data : $form.serialize(),
success: function(response) {
alert(response);
if(response == "Done") {
window.location.href = "home.php";
}
}
});
}
$('#submit').click(function(){ /* when the submit button in the modal is clicked, submit the form */
swal({
title: "Are you sure?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#ff5c33",
confirmButtonText: "Order Now!",
closeOnConfirm: false
},
function(isConfirm){
if (isConfirm) {
submit_order( $('#cakechoices'));
//swal("Deleted!", "Your imaginary file has been deleted.", "success");
}
});
return false;
});
希望有人可以帮助我!
答案 0 :(得分:1)
这是由于&#34;禁用&#34;属性。只需删除它和帖子&#34; branch_name&#34;将以空值发送。
您将其设置为已停用,结果是根本不会发送$ _POST [&#39; branch_name&#39;]变量。
将其更改为:
<option selected value="">-- Select one --</option>