朋友们,我在将用户详细信息插入数据库时创建了下拉日期。当我输入其中一个下拉日期时,它不会更新到数据库中,而是提供默认值1970-01-01。我已签入我的jquery行var end_date = $(“#end_date”)。val()当我发出警告时它会选择; t警告end_date的任何值。你能指出我哪里出错了,谢谢你提前。 chapter_subscription_search.php
<?php
include('db.php');
$start_date=date("Y-m-d");
?>
<html>
<head><title>Chapter Subscriptions</title>
<script src="js/jquery-1.12.4.js"></script>
<script src="js/jquery-ui.js"></script>
</head>
<body>
<header> <img src="images/ipoint.png" class="logo" /> USER REGISTRATION</header>
<div class="container">
<h1 style="text-align:center">ADDING THE CHAPTER SUBSCRIPTION DETAILS</h1>
<style>
#display {
color:red;
font-size:12px;
text-align:center;
}
.logo {
padding:5px;
float:left;
}
header {
background-color:#074e7c;
height:60px;
width:100%;
text-align:center;
color:white;
font-size:40px;
}
#wrap {
text-align:center;
}
</style>
<form name="chapter_subscriptions" id="chapter_subscriptions" action="#" method="post">
<table align='center' border='1'>
<tr>
<td> <label for="userid">UserId</label></td>
<td ><input id="userid" name="userid" type="text" /></td>
</tr>
<tr>
<td> <label for="chapter_no">ChapterNumber</label></td>
<td ><input id="chapter_no" name="chapter_no" type="text"/></td>
</tr>
<tr>
<td> <label for="start_date">StartDate</label></td>
<td ><input id="start_date" name="start_date" type="text"/></td>
</tr>
<tr>
<td> <label for="end_date">EndDate</label></td>
<td ><select name="end_date" id="end_date">
<option value=<?php $end_date = date('Y-m-d', strtotime("+3 months"));?>><?php echo $end_date; ?></option>
<option value=<?php $end_date = date('Y-m-d', strtotime("+6 months"));?>><?php echo $end_date;?> </option>
<option value=<?php $end_date = date('Y-m-d', strtotime("+9 months"));?>><?php echo $end_date;?> </option>
</select>
</td>
</tr>
<tr>
<td> <label for="chap_lic">License</label></td>
<td ><input id="chap_lic" name="chap_lic" type="text" /> </td>
</tr>
</table>
<div id="wrap">
<input type="submit" name="insert" id="insert" value="insert">
<input type="submit" name="edit" id="edit" value="edit">
</div>
</form>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#insert").click(function(e){
var userid = $("#userid").val();
var chapter_no = $("#chapter_no").val();
var start_date = $("#start_date ").val();
var end_date = $("#end_date").val();
var chap_lic = $("#chap_lic").val();
var dataString='userid='+userid+'&chapter_no='+chapter_no+'&start_date='+start_date+'&end_date='+end_date+'&chap_lic='+chap_lic;
alert(dataString);
if(userid==""||chapter_no==""||chap_lic=="") {
document.getElementById("display").innerHTML="Please Enter The Fields";
} else {
$.ajax({
type: "POST",
url: "chapter_subscription_insert.php",
data: dataString,
cache: false,
success: function(result){
//alert("submitted"+result);
$('#display').html(result);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
e.preventDefault();
}
});
});
</script>
<div id="display">
</div>
</body>
</html>
chapter_subscription_insert.php
<html>
<head><title>Insert</title></head>
<body>
<?php
include('db.php');
?>
<div id="display">
<?php
$userid=mysql_real_escape_string($_POST['userid']);
$chapter_no=mysql_real_escape_string($_POST['chapter_no']);
$start_date=mysql_real_escape_string($_POST['start_date']);
$start_date=date("Y-m-d");
$end_date1 = mysql_real_escape_string(($_POST['end_date']));
$end_date=date("Y-m-d",strtotime($end_date1));
//echo $end_date;
$chap_lic=mysql_real_escape_string($_POST['chap_lic']);
$str="insert into chapter_subscriptions(userId,chapter_no,start_date,end_date,chap_lic) values($userid,$chapter_no,'$start_date','$end_date','$chap_lic')";
$query=mysql_query($str);
if($query)
{
$display="Success";
} else {
$display="Failed";
}
echo $display;
?>
</div>
</body>
</html>
答案 0 :(得分:2)
你还没有回应选项的价值:
<select name="end_date" id="end_date">
<option value=<?php $end_date = date('Y-m-d', strtotime("+3 months"));?>><?php echo $end_date; ?></option>
<option value=<?php $end_date = date('Y-m-d', strtotime("+6 months"));?>><?php echo $end_date;?> </option>
<option value=<?php $end_date = date('Y-m-d', strtotime("+9 months"));?>><?php echo $end_date;?> </option>
</select>
将上述代码更改为
$enddate1 = date('Y-m-d', strtotime("+3 months"));
$enddate2 = date('Y-m-d', strtotime("+6 months"));
$endate3 = date('Y-m-d', strtotime("+9 months"));
<select name="end_date" id="end_date">
<option value=<?php echo $end_date1; ?>><?php echo $end_date1; ?></option>
<option value=<?php echo $end_date2; ?>><?php echo $end_date2; ?> </option>
<option value=<?php echo $end_date3;?>><?php echo $end_date3;?> </option>
</select>
答案 1 :(得分:0)
错误是您的下拉列表
value = "<?php echo $end_date = date('Y-m-d', strtotime("+3 months"));?>"
<select name="end_date" id="end_date">
<option value=<?php echo $end_date = date('Y-m-d', strtotime("+3 months"));?>><?php echo $end_date; ?></option>
<option value=<?php echo $end_date = date('Y-m-d', strtotime("+6 months"));?>><?php echo $end_date;?> </option>
<option value=<?php echo $end_date = date('Y-m-d', strtotime("+9 months"));?>><?php echo $end_date;?> </option>
</select>