-3

here i am displaying 2 database tables i.e 1 is after entering user details user information is displaying another is displaying 10 chapter allocation to the entered user from chapter_subscription table.In chapter_subscription table there are

  1. chapter number field
  2. start date
  3. end date

my aim is to create drop down option to end date so that user is allowed to choose it from the drop down.But my problem is i have used option tag ,when i run it is telling that unexpected for loop.Please can u help in resolving this error and make me to display drop down for each displayed end date.As i am newbie to php .Thank you in advance. 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>";
    ?>
Gaurav
  • 721
  • 5
  • 14
Vradhit
  • 59
  • 6

1 Answers1

0

Learn how you can debug your code! Check How to get useful error messages in PHP? to learn how you can enable detailed errors. I'd also suggest you check this handy guide for common mistakes. And use an IDE that checks for common mistakes, or use an online code validator. Stack Overflow is not a place to get debugging help, check What topics can I ask about here? for more information on what you can ask here.


1) You have a line without a semi-colon (before the for loop that causes the error):

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

which should be like this:

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

2) You have a while loop that never closes (missing a } somewhere in your script):

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

3) and...

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

should be

$display.="</select></tr>";
Community
  • 1
  • 1
Tom Udding
  • 2,264
  • 3
  • 20
  • 30