Course registration form

Discussion in 'PHP' started by moin, Apr 20, 2007.

  1. #1
    Hello,

    I have three courses, .net, j2ee, php with starting dates like 12-01-2007, 13-01-2007, 14-01,2007,

    the courses will be displayed in drop down box.
    the question is how to write the html code for this logic,


    if a user select .net then its starting date should be displayed i.e, 12-01-2007, if a user select j2ee then its starting should be displayed like 13-01-2007.

    Any help in this matter.

    Thanks.
     
    moin, Apr 20, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    you mean the html for it ??

    
    <select name="course">
    	<option value="12-01-2007">.NET</option>
    	<option value="13-01-2007">J2ee</option>
    	<option value="14-01-2007">PHP</option>
    </select>
    
    HTML:
     
    krakjoe, Apr 20, 2007 IP
  3. moin

    moin Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Courses should be displayed in one drop down list and immediately after it a text box should display the starting date,
    i.e when the user select .NET from the droop down list, its starting date should be displayed in the below text box i.e 12-01-07,

    how to write the code for this logic.

    Thanks.
     
    moin, Apr 20, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    
    
    </head>
    
    <body>
    <form name="mainform" method="post" action="">
    <select name="course" onchange="document.mainform.date.value = this.value">
    	<option value="">Choose a course</option>
    	<option value="12-01-2007">.NET</option>
    	<option value="13-01-2007">J2ee</option>
    	<option value="14-01-2007">PHP</option>
    </select>
    <input type="text" name="date" />
    </form>
    </body>
    </html>
    
    HTML:
     
    krakjoe, Apr 20, 2007 IP
  5. moin

    moin Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have created this table in the database

    <?php
    
    $con=mysql_connect("localhost","root","");
    
    if(!$con)
    {
    	echo "Error". mysql_error();
    }
    
    mysql_select_db("my_student7",$con);
    
    $sql="CREATE TABLE person(course varchar(30), date DATE)";
    
    
    
    if(mysql_query($sql,$con))
    {
    	echo "Table created";
    }
    else
    {
    	echo "Error". mysql_error();
    }
    
    mysql_close($con);
    
    ?>
    Code (markup):
    I am inserting the values in the database i.e., course and date values from the html form above in the database

    <?php
    if (!($con = mysql_connect("localhost","root","")))
        die('Could not connect: ' . mysql_error());
    else
        mysql_select_db( "my_student7", $con );
    
    
    $course=stripslashes(trim($_POST['course']));
    $date=stripslashes(trim($_POST['date']));
    
           
        if( mysql_query( "INSERT INTO person (course, date) VALUES ('$course', '$date')",$con) )
        {
            echo "Your details are added in the database and you can use this id, <b>$id</b>, for furture references";
        }
        else
        {
            echo "Your details could not be inserted at this time, please contact support";
        }
    
    mysql_close($con);
    ?>
    Code (markup):
    When i am trying to display the details i.e course and date, only date is displayed,

    `
    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }mysql_select_db("my_student7", $con);$result = mysql_query("SELECT * FROM person");
      
    echo "<table border='1'>";
      while($row = mysql_fetch_array($result, MYSQL_NUM))
      {
      echo "<tr><td>$row[0]</td><td>$row[1]</td></tr>";
      
      }echo "</table>";
      mysql_close($con);
    ?> 
    
    Code (markup):
    course is not displayed

    how to write the code for this logic.

    Thanks.
     
    moin, Apr 20, 2007 IP