Registration form

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

  1. #1
    Hello friends,

    I have used this html form for course registration,

    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD>
    
     <BODY>
     <form name="mainform" method="post" action="test_3.php">
    <select name="course" onchange="document.mainform.c_date.value = this.value">
        <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="c_date" />
    <input type="submit" value="submit"/>
    </form>
     </BODY>
    </HTML>
    Code (markup):
    I have inserted the values(course and date) in the database, here is the code for this,
    
    <?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 person2 (course, c_date) VALUES ('$date', '$course')",$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):
    But the main problem is, when I am trying to display the details, i.e course and details from the database only date is displayed but not the course, here is the code for it,
    
    `<?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }mysql_select_db("my_student5", $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):
    How to display the course.

    How to write the code for it.

    Any help.
     
    moin, Apr 20, 2007 IP
  2. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this
    
    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
    	die('Could not connect: ' . mysql_error());
    else
    	mysql_select_db("my_student5", $con);
    
    $result = mysql_query("SELECT * FROM person2");
    
    
    echo "<table border='1'>
    <tr>
    <th>Course</th>
    <th>Date</th>
    </tr>";
    
    while($row = mysql_fetch_array($result, MYSQL_NUM))
      {
      echo "<tr>";
      echo "<td>" . $row['0'] . "</td>";
      echo "<td>" . $row['1'] . "</td>";
      echo "</tr>";
      }
    echo "</table>";
    ?>
    
    PHP:
     
    MMJ, Apr 20, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    In your registration page, you're inserting into a database called person2, and in your other page it's called just person. That could be the problem. Also the database name is different.
     
    nico_swd, Apr 20, 2007 IP
  4. moin

    moin Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have changed the database name, actually the course value is not displayed.

    if we are using, <select name="course">
    <option value="12-01-12">.NET</option>
    </option>

    Only the date is displayed but not the course.

    how to rectify that.
     
    moin, Apr 20, 2007 IP