Drop down在php中不起作用

时间:2017-04-04 07:26:59

标签: php html mysql

这里我显示了2个数据库表,即1是在输入用户详细信息后显示另一个是从chapter_subscription表中向输入的用户显示10章分配。在chapter_subscription表中有

  1. 章节编号字段
  2. 开始日期
  3. 结束日期
  4. 我的目标是创建一个结束日期的下拉选项,以便允许用户从下拉列表中选择它。但我的问题是我使用了选项标签,当我运行时它告诉意外的循环。请发送你帮忙解决这个错误,并让我显示每个显示结束日期的下拉列表。我是php的新手。请提前告诉你。 insert_dummy.php

    <?php
    
        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 = '23456789abcdefghjkmnpqrstuvwxyz!@#$%^&*';
            $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("+1 months"));
         $end_date2 = date('Y-m-d', strtotime("+3 months"));
         $end_date3 = date('Y-m-d', strtotime("+6 months"));
         $end_date4 = date('Y-m-d', strtotime("+9 months"));
         $end_date5 = date('Y-m-d', strtotime("+12 months"));
         $page="";
    
    
        $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>";
    
    
        $display.="<tr><select>".$result['end_date'].
        for($i=0;$i<5;$i++)
        {
        $display.="<td><option value=echo $end_date1;>echo $end_date1;</option></td>";
        $display.="<td><option value=echo $end_date2;>echo $end_date2;</option></td>";
        $display.="<td><option value=echo $end_date3;>echo $end_date3;</option></td>";
        $display.="<td><option value=echo $end_date4;>echo $end_date4;</option></td>";
        $display.="<td><option value=echo $end_date5;>echo $end_date5;</option></td>";
    
        }
        $display.="</select></tr>"
        $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>";
        ?>
    

1 个答案:

答案 0 :(得分:0)

了解如何调试代码!检查How to get useful error messages in PHP?以了解如何启用详细错误。我还建议您检查this handy guide是否存在常见错误。并使用IDE检查常见错误,或使用在线code validator。 Stack Overflow不是获取调试帮助的地方,请查看What topics can I ask about here?以获取有关您可以在此处询问的内容的更多信息。

1)你有一行没有分号(导致错误的for循环之前):

$display.="<tr><select>".$result['end_date'].

应该是这样的:

$display.="<tr><select>".$result['end_date'];

2)你有一个永不关闭的while循环(在你的脚本中的某个地方缺少}):

while($result=mysql_fetch_array($query2)) {

3)和......

$display.="</select></tr>"

应该是

$display.="</select></tr>";