Form elements difference

Discussion in 'PHP' started by ghadacr, Aug 1, 2007.

  1. #1
    what it does is output the number of form elements based on the number that is entered, but my only problem is that it cant tell the difference between the different form elements: Help please...

    Thanks in advance...

    
    
    <?PHP include 'header.php'; ?>
    <?PHP include 'opendb.php'; ?>
    <?PHP
    
    $ClientDetailID = $_GET['ClientDetailID'];
    $numofpass = $_GET['numofpass'];
    $seatsnumber = $_GET['seatsnumber'];
    $FlightID = $_GET['FlightID'];
    
    $status = "OK"; // setting the flag for form validation
    $msg=""; // error message string is blank
    
    function check_field3($numofpass)
    {
      if(!preg_match("/[^0-9\ ]+$/",$numofpass))
        return TRUE;
      else
        return FALSE;
    }
    
    // Now let us check if name is entered or not
    if(strlen($FlightID) < 1 ){ // if name is less than two char length
    $msg .="<center>Please select a flight</center><BR>";
    $status="NOT OK";
    }
    
    // Now let us check if name is entered or not
    if(strlen($numofpass) < 1 ){ // if name is less than two char length
    $msg .="<center>Please enter a number for the amount of passengers travelling</center><BR>";
    $status="NOT OK";
    }
    
    
      if(!check_field3($numofpass))
    {
      
    $msg .="<center>Please enter a number for passenger numbers</center><BR>";
    $status="NOT OK";
    }
    
    if($status<>"OK"){ // if form validation is not passed
    echo "<BR><BR>";
    echo $msg. "<br><center><input type='button' value='Retry' onClick='history.go(-1)'></center><br><br><br>";
    
    }else{
    
    
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    
    <script language="JavaScript" src="javascript/ts_picker.js">
    </script>
    <script type="text/javascript" src="javascript/calendarDateInput.js">
    </script>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?PHP 
    if($numofpass > $seatsnumber) {
    	
    	echo "
    <font size=+2>The number of seats left(<font color=#FF0000>$seatsnumber</font>) 
    is less than the seats requested (<font color=#FF0000>$numofpass</font>). Please 
    go back and enter a number that equals or is less than the number of seats left.</font><br><br>
     <input type='button' value='Back' onClick='history.go(-1)'> ";
    	
    	} else {
    	
    	
    
    ?>
    <form action="process_hotel.php" method="get" name="add_hotel">
    
      <table width="85%" border="0" align="center">
        <tr> 
          <td colspan="2"><strong>Client flight confirmation</strong></td>
        </tr>
        <tr> 
          <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td></td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td></td>
        </tr>
        <?PHP 
    	
    	
    	
    	while ($numofpass>0) {
    
    	
    	echo"  <tr>
    	 
          <td><strong>Title:</strong></td>
          <td><select name=title>
    	  	 <option value=></option>
              <option value=Mr>Mr</option>
              <option value=Mrs>Mrs</option>
              <option value=Ms>Ms</option>
              <option value=Master>Master</option>
            </select></td>
        </tr>
        <tr> 
          <td><strong>First name:</strong></td>
          <td><input type=text name=firstname></td>
        </tr>
        <tr> 
          <td height=32><strong>Surname:</strong></td>
          <td><input type=text name=surname></td>
        </tr>
        <tr> 
          <td><strong>Child/Adult:</strong></td>
          <td><select name=ChildAdult>
    	  	  <option value=></option>
              <option value=1>Child</option>
              <option value=2>Adult</option>
            </select></td>
        </tr>
        <tr> 
          <td><strong>Cost:</strong></td>
          <td><input type=text name=cost></td>
        </tr>
        <tr> 
          <td width=17><strong>Notes:</strong></td>
          <td width=83><textarea name=notes></textarea></td>
    	 </tr>
    	 <tr>
    	 <td></td></tr>"
    	;
    
    	$numofpass = $numofpass-1;
    	
    	
    }
    	?>
        <tr> 
          <td colspan="2"> <input type="submit" name="submit" value="Confirm flight"> 
            <input type="reset" name="Reset" value="Reset"> <INPUT type="button" value="Cancel" onClick="location.href='http://pb-sql/admin.php'"> 
          </td>
        </tr>
      </table>
    </form>
    <?php }}?> 
    </body>
    </html>
    <?PHP include 'footer.php'; ?>
    
    
    
    PHP:
     
    ghadacr, Aug 1, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Convert them to arrays:
    
    <select name="title[]">
    
    Code (markup):
    
    <textarea name="notes[]"></textarea>
    
    Code (markup):
    ....
     
    nico_swd, Aug 1, 2007 IP
  3. ghadacr

    ghadacr Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok i done that but, i'm not to sure on how the process will work once the arrays is passed:Here is the process page where the arrays will come into:

    <?PHP include 'opendb.php'; ?>
    
    <?PHP include 'header.php'; ?>
    
    <?php 
    
    $title   = $_GET['title'];
    $firstname  = $_GET['firstname'];
    $surname  = $_GET['surname'];
    $ChildAdult  = $_GET['ChildAdult'];
    $cost  = $_GET['cost'];
    $noAtes  = $_GET['notes'];
    
    
    
    foreach() 
      { 
    //----Query 5------
    $query = mssql_init ("sp_insertFlightSpaces"); 
    
    mssql_bind($query, "@FlightID", $surname, SQLVARCHAR);
    
    mssql_bind($query, "@ChildOrAdult", $UserNames, SQLVARCHAR);
    
    mssql_bind($query, "@ClientDetailID", $newheld, SQLINT2);
    
    mssql_bind($query, "@cost", $forename, SQLVARCHAR);
    
    mssql_bind($query, "@notes", $forename, SQLVARCHAR);
    
    mssql_bind($query, "@Title", $forename, SQLVARCHAR);
    
    mssql_bind($query, "@FirstName", $forename, SQLVARCHAR);
    
    mssql_bind($query, "@Surname", $forename, SQLVARCHAR);
    
    
    if (($result = mssql_execute($query)) === false) 
    { 
        die('Could not execute the query query 2(Insert client)'); 
    } 
    
    ///--------------------------------------------
    
    
    	}
    
    	
    						
    	
    mssql_close()
    
    ?>
    <?PHP include 'footer.php'; ?>
    
    PHP:
     
    ghadacr, Aug 1, 2007 IP
  4. ghadacr

    ghadacr Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Any help please..........
     
    ghadacr, Aug 2, 2007 IP