0
在這裏,我將添加用戶信息,當我添加用戶信息數據插入用戶表和10編號從1到10編號分配給同一個用戶,並得到插入到數據庫行chapter_subscription中。在訂閱表的章節中,我們將章節號,開始日期,結束日期作爲表名稱。但是我希望允許用戶將結束日期分別更改爲1或3或6或9或12個月下拉風格的形式。我想知道如何創建一個下拉顯示章節訂閱的結束日期。我是新來的PHP請幫助我,謝謝你。 insert_dummy.php下拉選項在PHP中選擇結束日期嵌入HTML
<html>
<head><title>Insertion</title>
</head>
<body>
<style>
#colour {
text-decoration:none;
}
</style>
<div id="display">
<?php
error_reporting(0);
include('db.php');
$userName=mysql_real_escape_string($_POST['userName']);
$userEmail=mysql_real_escape_string($_POST['userEmail']);
$userPassword=mysql_real_escape_string($_POST['userPassword']);
$expiry_date1=mysql_real_escape_string($_POST['expiry_date']);
$expiry_date=date("Y-m-d" ,strtotime($expiry_date1));
$end_date1=mysql_real_escape_string($_POST['end_date']);
$end_date=date("Y-m-d",strtotime($end_date1));
$regDate = date("Y-m-d");
function generateCode($characters)
{
$possible = '[email protected]#$%^&*';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
$registration_key=generateCode(10);
$str="insert into coeds_user(userName,userEmail,userPassword,regDate,expiry_date,registration_key) values('$userName','$userEmail','$userPassword','$regDate','$expiry_date','$registration_key')";
$query=mysql_query($str);
$userid=mysql_insert_id();
if($query)
{
$display="Success";
}
else
{
$display= "Failed";
}
$string="select * from coeds_user where userId=$userid";
$query2=mysql_query($string);
$display.="<table border='1' align='center'>";
$display.="<tr><th>UserName</th><th>UserEmail</th><th>UserPassword</th><th>RegDate</th><th>ExpiryDate</th><th>RegistrationKey</th><th colspan='3'>Action</th></tr>";
while($result=mysql_fetch_array($query2))
{
$display.="<tr>";
$display.="<td>".$result['userName']."</td>";
$display.="<td>".$result['userEmail']."</td>";
$display.="<td>".$result['userPassword']."</td>";
$display.="<td>".$result['regDate']."</td>";
$display.="<td>".$result['expiry_date']."</td>";
$display.="<td>".$result['registration_key']."</td>";
$display.="<td><a id='colour' class='tooltip' title='Edit' href='user_update.php?user_Id=".$result['userId']."'><img id='image' src='./images/small.gif'/></a></td>";
$display.="<td><a id='colour' class='tooltip' data-toggle='tooltip' title='Delete' href='user_delete.php?user_Id=".$result['userId']." '><img id='image' src='./images/trash.png'/></a></td>";
$display.="</table>";
$end_date1 = date('Y-m-d', strtotime("+3 months"));
$end_date2 = date('Y-m-d', strtotime("+6 months"));
$end_date3 = date('Y-m-d', strtotime("+9 months"));
$page="";
<?php
}
$str="select chapter_no from chapter_details ";
$query7=mysql_query($str);
$count=mysql_num_rows($query7);
for($i=0;$i<$count;$i++)
{
$chap_lic=generateCode(50);
$chapter_no=mysql_result($query7,$i,'chapter_no');
$start_date=date('Y-m-d');
$expiry_date=mysql_real_escape_string($_POST['end_date']);
$end_date=date("Y-m-d" ,strtotime("+3 months"));
/*$end_date1=mysql_real_escape_string($_POST['end_date']);
$end_date=date("Y-m-d",strtotime($end_date1));*/
$s="insert into chapter_subscriptions (userId,chapter_no,start_date,end_date) values($userid,$chapter_no,'$start_date','$end_date')";
$end_date=date("Y-m-d" ,strtotime("+3 months"));
$query8=mysql_query($s);
}
$strings="select * from chapter_subscriptions where userId=$userid";
$query9=mysql_query($strings);
$display.="<table border='1' align='center'>";
$display.="<tr><th>ChapterNumber</th><th>StartDate</th><th>EndDate</th><th colspan='2'>Action</th></tr>";
while($result=mysql_fetch_array($query9))
{
$display.="<tr>";
$display.="<td>".$result['chapter_no']."</td>";
$display.="<td>".$result['start_date']."</td>";
for(i=1;i<12;i+2)
{
$display.="<td>".$result['end_date']."</td>";
}
$display.="<td><a id='colour' class='tooltip' title='Edit' href='chapter_subscription_update.php?user_Id=".$result['userId']."'><img id='image' src='./images/small.gif'/></a></td>";
$display.="<td><a id='colour' class='tooltip' data-toggle='tooltip' title='Delete' href='chapter_subscription_delete.php?user_Id=".$result['userId']." '><img id='image' src='./images/trash.png'/></a></td>";
$display.="</tr>";
}
$display.="</table>";
echo $display;
?>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#expiry_date").datepicker();
$("#menuwrapper").hide();
$("#unicode").click(function() {
$("#menuwrapper").slideToggle(500);
});
});
</script>
</body>
</html>
我還沒有創建任何字段來輸入結束日期。當我輸入用戶名,用戶密碼,用戶電子郵件和有效期限時,這些詳細信息將同時插入到用戶表中,同時章節號從1到10以及開始日期和結束日期也添加到chapter_subscription表中,所以當我顯示這個結束日期字段時,我需要創建下拉菜單。 –
這***是***下拉字段**插入結束日期。提到的文件只會處理插入到數據庫中。 –