Solved

Populate fields from Listbox

Posted on 2007-12-02
16
295 Views
Last Modified: 2013-12-12
OK, I have a form in a php file.  
The first field on the form is a listbox.  THe user needs to select an entry from the list box.
Once the entry is selected, a query is run.  THe results of the query are put into a "table" on the page.
THen the user fills in the rest of the form.
On completion of the entry, the user hits the submit button.  The form then goes to a validation.php file.
If all passes the validation, the user then goes to a second page (second form) that gets more input.
Once that page is filled out and the user hits Submit, everything (all input data from both pages) is saved to a database.  After the database is updated, the user then gets a printable page back (where the fields they inputted are merged into some text) that they can then print out.

I can get the List box field on page 1 filled using a while loop using results from a query.
I can get the form submit on page 1 to go to the Validation.php script using the "action=" for the form.
I can store the inputted data (via $_SESSION variables) so I can save to the database.

My problems are:
1.  I can't figure out how to do an automatic data retrieve when the user has made a selection from the list box.  And stay on the same page to continue data entry.  I've read several previous solutions and one came close, but can't quite figure it out completely.

2.  I'm not sure if the "header........." will send the user to the second page from the validation.php script.
     I need to be able to go from the Validation.php to the second page.  Or come back to the first page if the validation does not pass.  As an alternative, I could come back to the first page with a variable that is set to TRUE (maybe) if the validation was successful or false if unsuccessful?  THen decide whether to stay on the page or continue to the next page.

What I am looking for is an explanation with examples of how to accomplish the 2 things I've asked.  I am using (and new to) PHP.  I am also using mySQL (with no real problem there).  I prefer not to add javascript into the mix, but will consider it if a really good example is provided.

Depending on how good the answers are, there could be bonus points.  So try and be complete.  Remember, I'm fairly New to PHP.

Thanks in advance.
OldHatt45
0
Comment
Question by:OldHatt45
  • 8
  • 8
16 Comments
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
Hello
I will show you how I do similar things (maybe someone have better solution)
Please look in code below:

I do everything on one page (validation and forms).
In your case you can have three diferent forms   from1.html form2.html form3.html and include diferent forms for user.

for he first problem you should use javascript or AJAX if you want to do this right after changeing selected item in listbox.
Other way is to create listbox in form and submit button. (page will reload and depending on value selected in listbox you must include diferent form file)

If you need more exapmles or information just ask.
Best Regards
FooKy



/********************** page1.php ***********************/

<?php
 

 $css_error_prfx = ' style="background-color:#FCB188;" ';
 

$val_name = '';

$val_age = '';

$css_name = '';

$css_age = '';
 

$validate_msg = 'OK';
 

if(isset($_REQUEST['action'])){

   if($_REQUEST['action']=='Continue'){

      include_once('validate.php');

      if($validate_msg == 'OK' ){

        //Do something for example go to another page or store in database 

      }

   }// action == continue

   

}//isset action 

  

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

  <meta http-equiv="content-type" content="text/html; charset=windows-1250">

  <meta name="generator" content="PSPad editor, www.pspad.com">

  <title></title>

  </head>

  <body>

  

  <?php 

    if($validate_msg != 'OK' ){

      echo "<h3> $validate_msg </h3>";

    }

  ?>

  

    <form action="page1.php" method="post">

      Name: <input type="text" name="name" 

              value="<?php echo $val_name?>" <?php echo $css_name ?>/><br />

      Age:  <input type="text" size="2" name="age" 

              value="<?php echo $val_age?>" <?php echo $css_age?> /><br />

      <input type="submit" name="action" value="Continue" />

    </form>

  

  

  </body>

</html>

/********************** page1.php ***********************/

/********************** validate.php ***********************/

<?php

        

        

        if($_REQUEST['name']==''){

            $css_name=$css_error_prfx;

            $validate_msg = 'Please fill in required information';

        }else{

            $val_name=$_REQUEST['name'];

        }

        

         if($_REQUEST['age']==''){

            $css_age=$css_error_prfx;

            $validate_msg = 'Please fill in required information';

        }else{

            $val_age=$_REQUEST['age'];

            if(!is_numeric($val_age)){

               $css_age=$css_error_prfx;

               $validate_msg = 'This is not valid number';

          }

        }
 

?>

/********************** validate.php ***********************/

Open in new window

0
 

Author Comment

by:OldHatt45
Comment Utility
Fooky,

The example provided does not address the questions.  
First, I asked for an example and description about the "LISTBOX"  there is NO listbox mentioned in the example.  Second, I asked for information regarding how to "Automatically" retrieve the the information  based on a user selection of an option in the listbox.  I did not ask for the use of a submit button.    WHere in the  Validate.php example do you redirect the user to the 2nd page???  I don't see that either.  Please re-read what I have asked for.  Also, I do NOT want to use javascript or AJAX (whatever that is)  unless absolutely necessary (and I don't believe it is necessary).   Thanks, for the try but unless I'm really missing something none of the questions I asked were answered.  And just t he code with no explanation is also very little help.

OldHatt45
0
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
OK. If you want step by sten solution here it is.
First for your first question and then I'll post one comment for each of your problems.

"Also, I do NOT want to use javascript or AJAX (whatever that is)  unless absolutely necessary (and I don't believe it is necessary).  "

You can ask why? Because PHP is server side language and you want to react to user behaviour .
So user must tell your server what he want to do. either by submiting form (like in my example) or by submiting it automaticly by javascript (like my example) or if you dont want to reload form you must use AJAX.

Best Regards
FooKy


/************************** page2.php ************************/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

  <meta http-equiv="content-type" content="text/html; charset=windows-1250">

  <meta name="generator" content="PSPad editor, www.pspad.com">

  <title></title>

  </head>

  <body>
 

<?php

switch (@$_REQUEST['listVal']) {

    case 1:

        include('form1.html');

        break;

    case 2:

        include('form2.html');

        break;

    default:

        include('listbox.html');

}

?>

  </body>

</html>

/************************** page2.php ************************/

/************************** listBox.html ************************/

<form action="page2.php" method="post" >

<select name="listVal" onchange='this.form.submit()'>

  <option title="none" name="none">Please select something</option>

  <option title="Form1" name="form1" value="1">Form 1</option>

  <option title="Form2" name="form2" value="2">Form 2</option>

</select>

<br />

<input type="submit" name="action" value="Show Form">

</form>

/************************** listBox.html ************************/

/************************** form1.html ************************/
 

    <form action="page2.php" method="post">

      Name: <input type="text" name="name" 

              value="<?php echo $val_name?>" <?php echo $css_name ?>/><br />

      Age:  <input type="text" size="2" name="age" 

              value="<?php echo $val_age?>" <?php echo $css_age?> /><br />

      <input type="submit" name="action" value="Continue" />

    </form>
 

/************************** form1.html ************************/

/************************** form2.html ************************/

 <form action="page2.php" method="post">

      First Name: <input type="text" name="fname" /><br />

      Last Name: <input type="text" name="lname" /><br />

      <input type="submit" name="action" value="Continue" />

    </form>

/************************** form2.html ************************/

Open in new window

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
Hello,
You asked me:
"Where in the  Validate.php example do you redirect the user to the 2nd page??? "

Please try to look again into my code (from first response):
Line 17: "//Do something for example go to another page or store in database "

You can redirect using header() function.

Best Regards
FooKy
if($_REQUEST['action']=='Continue'){

      include_once('validate.php');

      if($validate_msg == 'OK' ){

        //Do something for example go to another page or store in database 

      }

   }// action == continue

Open in new window

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
Hello

If more explanation is needed just ask.

Best Regards
FooKy
0
 

Author Comment

by:OldHatt45
Comment Utility
Fooky,

OK, Let me look at it with the new info you provided.
I won't be able to until tonight, so, until later on.........

Thanks

OldHatt45
0
 

Author Comment

by:OldHatt45
Comment Utility
Fooky, et.al.

OK, I'm still having trouble.  To me it looks like the 2nd example is on the right track, but I can't seem to figure out some of it.  It looks like the only thing on "the first page"  which I think is page2.php, to start with is the list box.  But I'm not sure.  It then looks like depending on what the user selects it then includes either form1 or form2.  Form1 has some fields on it and so does form2.  OK, this is good, but not quite there.  What I have done is to strip down my code into something Very basic.  

The List box is the key to this whole thing.  If the user enters this page from say the "Home" page the list box is supposed to display (and that works).  The default "Future" is selected and the user just continues to fill in the Person fields, hits the submit button and is taken to the AdtProc1.php file where processing/validation occurs.  If the validation is successful the user goes to "SecondPage.php"  If the validation is NOT successful the user goes back to FirstPage.php and fixes the input fields that need fixing.  

OK, now, If the user makes another selection from the list box the AgeYrs and AgeMos fields are obtained from the database (or are supposed to be) and the table is filled in.  Then the user goes on to fill in the Person Name fields.  Again, going tothe validation page. Same as before.

Last, the user can come into the FirstPage.php and already have the Name, AgeYrs and AgeMos fields filled in.  In which case the user just fills in the Person Name and goes on to validation, same as before.

So here is the code I have.  I can't figure out how to change it so that everything works the way you described.   Sorry the code is not formatted very well, but it didn't come over very good.  
Also, sorry for being a pain in the butt, but I'm having trouble getting the concepts.

I appreciate your HELP

OldHatt45

/**************************** FirstPage.php *********************************************************/
<?php
      require_once('ARD_fns.php');
      require_once('Connections/ARDMSQL1.php');
      session_start();
      // $_SESSION['AMDIDNo'] = '10272007-1';
      // $_SESSION['AMDName'] = 'Gracie';
      $_SESSION['AMDIDNo'] = NULL;
      $_SESSION['AMDName'] = NULL;


mysql_select_db($database_ARDMSQL, $ARDMSQL1 );
$query_rsDAMe = "SELECT ARDnumber, DName, DAgeYrs, DAgeMos FROM Dots WHERE ARDnumber = '" .$_SESSION['AMDIDNo']. "' AND DName = '" .$_SESSION['AMDName']."'";

$rsDAMe = mysql_query($query_rsDAMe, $ARDMSQL1) or die(mysql_error());
$row_rsDAMe = mysql_fetch_assoc($rsDAMe);
$totalRows_rsDAMe = mysql_num_rows($rsDAMe);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>First Page</title>
<?php
      if ( (isset( $_SESSION['AMDName'])) && (isset( $_SESSION['AMDIDNo'])) ) {
            //We set up the query for the info for that particular Name-ID ;
            mysql_select_db($database_ARDMSQL, $ARDMSQL1);
            if ( ! $ARDMSQL1) {
                 die( "Couldn't connect to MySQL:  ".mysql.error() );
            }
            $query_rsDAMe = "SELECT ARDnumber, DName, DAgeYrs, DAgeMos FROM Dots WHERE ARDnumber = '" .$_SESSION['AMDIDNo']."' AND DName = '" .$_SESSION['AMDName']. "'" ;
            $rsDAMe = mysql_query($query_rsDAMe , $ARDMSQL1 ) or die(mysql_error());
                $row_rsDAMe = mysql_fetch_assoc($rsDAMe);
            $totalRows_rsDAMe = mysql_num_rows($rsDAMe);
 // echo "Performing the single row query.  Total Rows is $totalRows_rsDAMe";
            $AdUseLB = false;  
// echo "Down to UseLB = false";
            if ($totalRows_rsDAMe > 0) {
                $_SESSION['DAMYears'] = $row_rsDAMe['DAgeYrs'];
                  $_SESSION['DAMMos'] = $row_rsDAMe['DAgeMos'];
            } else {
                  $_SESSION['DAMYears'] = NULL ;
                  $_SESSION['DAMMos'] = NULL ;
            }
// echo "End of SESSION assign section";
      } else {
          //We set up for the List box entries and populate it allowing for the SINGLE selection.
            mysql_select_db($database_ARDMSQL,$ARDMSQL1 );
            if ( ! $ARDMSQL1) {
                 die( "Couldn't connect to MySQL:  ".mysql.error() );
            }
            
            $query_rsDAMe = "SELECT ARDnumber, DName FROM Dots WHERE Disposition = 'f' || Disposition = 'r' ORDER BY DName ";
            $rsDAMe = mysql_query($query_rsDAMe, $ARDMSQL1)  or die(mysql_error());
            $totalRows_rsDAMe = mysql_num_rows($rsDAMe);
            if ($totalRows_rsDAMe > 0) {
                $AdUseLB = true;
            }
      }
?>
</head>

<body>
<table width="100%" height="162" border="0">
  <tr>
    <th width="15%" valign="top" bgcolor="#8D8DEF" scope="row">      <p>
<a href="http://aldr/index.htm"><img src="/images32/buttonhome.JPG" alt="" name="ButtonHome" width="137" height="30" vspace="5" border="0"></a>      
<a href="http://aldr/FirstPage.php"><img src="/images32/buttonAdt.JPG" alt="" name="ButtonAdt" width="137" height="30" vspace="5" border=0>
    <p>&nbsp;</p></th>
    <td width="85%" valign="top" bgcolor="#8D8DEF">
        &nbsp; <h1 align="center" class="style4">Some Introductory Information </h1>
      <p align="left" class="style6">Filling in the information requested below,  is the first step in the process. </p>

      <!-- I think the Action=adt1Proc.php for the frmAdt1 is correct but I'm NOT SURE - need to test -->
       <form action="Adt1Proc.php" method="post" name="frmAdt1" id="frmAdt1">  
        <table width="100%"  border="0" cellspacing="3" cellpadding="3">
        <tr>
          <th width="7%" scope="row">Name:</th>
          <!-- Here we need to set up the list box or just a plain text field depending on where they came from. -->
          <!-- So an if statement where we check the came from will determine what happens. -->
          <!-- THIS WORKS -->
          <td width="25%" bgcolor="#8D8DEF">
        <?php
      if ( $AdUseLB ) {
                        // echo "Am using the List Box";
                        ?>                  
               <select name="selectedD" size="1" style="width:275" onChange=" <?php $_SESSION['AMDIDNo'] = $_POST['selectedD'] ?>;MM_callJS('getDobeInfo ($_SESSION[\'AMDName\'], $_SESSION[\'AMDIDNo\'])')" >
      <option value="11111111" selected> Future </option>
                <?php      
                // Then populate the array to hold all the available names and numbers.
                while ($row_rsDAMe = mysql_fetch_assoc($rsDAMe)) {
                ?>
        <option  value=" <?php echo $row_rsDAMe['ARDnumber']; ?>"  > <?php echo $row_rsDAMe['Name']; ?>  </option> <?php
      }
      // On selection of a name we want to query the database and populate the fields.
      ?>
        </select>
      <?php      
      // We get the ARDNumber from the rsDAMe recdset as the value of the select listbox and perform the query.

      if ( $_SESSION['AMDIDNo'] <> "11111111" ) {      
           mysql_select_db($database_ARDMSQL,$ARDMSQL1 );
           if ( ! $ARDMSQL1) {
                     die( "Couldn't connect to MySQL:  ".mysql.error() );
            }
      $query_rsDAMe = "SELECT ARDnumber, DName, DAgeYrs, DAgeMos FROM Dots WHERE ARDnumber = '" .$_SESSION['AMDIDNo']."'" ;

      $rsDAMe = mysql_query($query_rsDAMe, $ARDMSQL1 ) or die(mysql_error());
                      $row_rsDAMe = mysql_fetch_assoc($rsDAMe);
       $totalRows_rsDAMe = mysql_num_rows($rsDAMe);
      if ($totalRows_rsDAMe > 0) {
            $_SESSION['AMDName'] = $row_rsDAMe['DName'] ;
            $_SESSION['DAMYears'] = $row_rsDAMe['DAgeYrs'];
            $_SESSION['DAMMos'] = $row_rsDAMe['DAgeMos'];
      } else {
            $_SESSION['AMDName'] = NULL ;
            $_SESSION['DAMYears'] = NULL ;
            $_SESSION['DAMMos'] = NULL ;                        }
             } else {
                  $_SESSION['AMDName'] = NULL ;
                  $_SESSION['DAMYears'] = NULL ;
                  $_SESSION['DAMMos'] = NULL ;
                   }
            } else {
            // We already have a Name, so we just want to populate the fields.
            $_SESSION['DAMYears'] = $row_rsDAMe['DAgeYrs'];
            $_SESSION['DAMMos'] = $row_rsDAMe['DAgeMos'];
                                          }
            ?>
      <input name="selectedD" type="text" value=" <?php echo $_SESSION['AMDName']; ?> " size="30" maxlength="30">
      <?php      }  ?>
          </td>
          <td width="13%">Age (Approx): </td>
          <td width="24%" bgcolor="#8D8DEF">&nbsp;
      </td>
          <td width="13%">Age (Approx): </td>
          <td width="24%" bgcolor="#8D8DEF">&nbsp;
            <?php
              if ( $_SESSION['AMDIDNo'] <> "11111111" ) {      
                 echo $_SESSION['DAMYears']." year(s) and ".$_SESSION['DAMMos']." months old" ;
                    } ?>
        </td>
        </tr>
      </table>       
        <?php
          // Here we need to build the AID number.
            $ADRAID = "ADR".date("YmdHis");
            $_SESSION['AMAID'] = $ADRAID ;
        ?>
        <p align="left" class="style4">Person Information:&nbsp; <input type="hidden" name="AIDNo" value="<?php print $ADRAID ?>" />  </p>
        <table width="72%"  border="0" cellspacing="3" cellpadding="3">
        <tr>
          <th width="7%" scope="row"><div align="left">Name:</div></th>
          <td width="7%">(First)</td>
          <td width="22%" bgcolor="#8D8DEF">
            <input name="txtFName" type="text" id="txtFName" size="25" maxlength="25">
                  <?php $_SESSION['AFname'] = "txtFName" ?>
          </td>
          <td width="6%">(M.I.)</td>
          <td width="3%" bgcolor="#8D8DEF">
                <input name="txtMI" type="text" size="2" maxlength="1">
                  <?php $_SESSION['AMInit'] = "txtMI" ?>
              </td>
          <td width="8%">(Last)</td>
          <td width="47%" bgcolor="#8D8DEF">
              <input name="txtLName" type="text" size="30" maxlength="30">
              <?php $_SESSION['AMLname'] = "txtLName" ?>
              </td>
        </tr>
      </table>       
          <br>
            <!-- The Submit Button should take us to the Validation.php file -->
        <div align="center"> <input type="submit" name="SubmitA1" value="Submit My Application Step 1">
         &nbsp;
         <!-- the reset button should clear everything and redisplay the current page only. -->
       <input type="reset" name="StartOver" value="Start Over">
         &nbsp;&nbsp;
       <!-- // The cancel button should take the user back to the beginning page I think. -->
         <input type="submit" name="Cancel" value="Cancel">
        </div>
    </form>       
      </td>
  </tr>
</table>
 </body>
</html>
 
/*************************** End FirstPage.php ************************************************/
/*************************** SecondPage.php ************************************************/

<!-- A Full Page of Fields in Table Format -->
<!--  tHE submit button sends the input from Secondpage.php to it's validation2.php file -->

/************************ End of SecondPage.php ********************************************/

<!--  And then if it passes validation, firstpage and secondpage input gets saved to the database.  -->
<!-- Finally ThirdPage.php displays a Print Ready document with info from FirstPage and SecondPage. ->

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
Hello.

Wow your code is totally messed up.

First thing.
VERY IMPORTATNT.  PHP is server side script. When your browser get page its only html generated by php.
So you cannot do things like this
<select name='dsad' onChange="<?php $_SESSION['dsad'] = $_POST['dsad'] ?>" />


Ok back to code.

I've changed it to what I think you want to get :)
If you need to set txtFName , txtMI etc. as session variables then change second form action to FirstPage.php and then on beging add
if(isset($_POST['SubmitA1']){
$_SESSION['varName'] = $_POST['varName'];
header('Location: http://adress_to_my_site/frmAdt1.php');
}

//REMEMBER THAT this should be on beginig

Best Regards
FooKy

PS. I hope that now you should handle.
<?php

 require_once('ARD_fns.php');

      require_once('Connections/ARDMSQL1.php');

      session_start();

      

    

    if(isset($_POST['Cancel']){

      header('Location: http://myweb.com/Home.html');

    }

    

      

// DATA for List BOX

            mysql_select_db($database_ARDMSQL,$ARDMSQL1 );

            if ( ! $ARDMSQL1) {

                 die( "Couldn't connect to MySQL:  ".mysql.error() );

            }

            

            $query_rsDAMe = "SELECT ARDnumber, DName FROM Dots WHERE Disposition = 'f' || Disposition = 'r' ORDER BY DName ";

            $rsLB = mysql_query($query_rsDAMe, $ARDMSQL1)  or die(mysql_error());

            $totalRows_rsLB = mysql_num_rows($rsLB);
 

if(!isset($_SESSION['AMDIDNo'])){            

  $_SESSION['AMDIDNo'] = "11111111";

}
 

if(isset($_REQUEST['selectedD']){ // User selected someting else then Future = 111111111

  $_SESSION['AMDIDNo'] = $_REQUEST['selectedD'];

  

  //Get Age 

      mysql_select_db($database_ARDMSQL,$ARDMSQL1 );

           if ( ! $ARDMSQL1) {

                     die( "Couldn't connect to MySQL:  ".mysql.error() );

            }

      $query_rsDAMe = "SELECT ARDnumber, DName, DAgeYrs, DAgeMos FROM Dots WHERE ARDnumber = '" .$_SESSION['AMDIDNo']."'" ;
 

      $rsDAMe = mysql_query($query_rsDAMe, $ARDMSQL1 ) or die(mysql_error());

                      $row_rsDAMe = mysql_fetch_assoc($rsDAMe);

       $totalRows_rsDAMe = mysql_num_rows($rsDAMe);

      if ($totalRows_rsDAMe > 0) {

            $_SESSION['AMDName'] = $row_rsDAMe['DName'] ;

            $_SESSION['DAMYears'] = $row_rsDAMe['DAgeYrs'];

            $_SESSION['DAMMos'] = $row_rsDAMe['DAgeMos'];

      } else {

            $_SESSION['AMDName'] = NULL ;

            $_SESSION['DAMYears'] = NULL ;

            $_SESSION['DAMMos'] = NULL ;         

      }  

}
 

?>
 
 
 
 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

  <meta http-equiv="content-type" content="text/html; charset=windows-1250">

  <meta name="generator" content="PSPad editor, www.pspad.com">

  <title></title>

  </head>

  <body>

  <table width="100%" height="162" border="0">

  <tr>

    <th width="15%" valign="top" bgcolor="#8D8DEF" scope="row">      <p>

<a href="http://aldr/index.htm"><img src="/images32/buttonhome.JPG" alt="" name="ButtonHome" width="137" height="30" vspace="5" border="0"></a>      

<a href="http://aldr/FirstPage.php"><img src="/images32/buttonAdt.JPG" alt="" name="ButtonAdt" width="137" height="30" vspace="5" border=0>

    <p>&nbsp;</p></th>

    <td width="85%" valign="top" bgcolor="#8D8DEF">

        &nbsp; <h1 align="center" class="style4">Some Introductory Information </h1>

      <p align="left" class="style6">Filling in the information requested below,  is the first step in the process. </p>

      <form action="FirstPage.php" method="post" >

        <table width="100%"  border="0" cellspacing="3" cellpadding="3">

          <tr>

           <th width="7%" scope="row">Name:</th>

           <td width="25%" bgcolor="#8D8DEF">

              

                  <select name="selectedD" size="1" style="width:275" onchange='this.form.submit()'>

                    <option value="11111111"> Future </option>

                <?php      

                  while ($row_rsLB = mysql_fetch_assoc($rsLB)) {

                ?>

                    <option  value=" <?php echo $row_rsLB['ARDnumber']; ?>" <?php if($_SESSION['AMDIDNo'] ==$row_rsLB['ARDnumber']) echo "selected" ?> > 

                      <?php echo $row_rsLB['Name']; ?> 

                    </option> 

                <?php

                  }

                ?>

                  </select> 

            </td>

          </tr>

          <tr>

            <td width="13%">Age (Approx): </td>

            <td width="24%" bgcolor="#8D8DEF">&nbsp;

              <?php 

                echo @$_SESSION['DAMYears'] 

              ?>

            </td>

          </tr>

          <tr>

            <td width="13%">Age Mos (Approx): </td>

            <td width="24%" bgcolor="#8D8DEF">&nbsp;

              <?php

                echo @$_SESSION['DAMMos'];

              ?>

            </td>

          </tr>

          <tr>

            <td colspan="2">

              <input type="submit" name="action" value="Select">

            </td>

          </tr>

        </table>

       </form>

        

      <form action="Adt1Proc.php" method="post" name="frmAdt1" id="frmAdt1">

        <p align="left" class="style4">Person Information:&nbsp; 

         <input type="hidden" name="AIDNo" value="<?php print $ADRAID ?>" />  </p>

        <table width="72%"  border="0" cellspacing="3" cellpadding="3">

        <tr>

          <th width="7%" scope="row"><div align="left">Name:</div></th>

          <td width="7%">(First)</td>

          <td width="22%" bgcolor="#8D8DEF">

            <input name="txtFName" type="text" id="txtFName" size="25" maxlength="25">

                  

          </td>

          <td width="6%">(M.I.)</td>

          <td width="3%" bgcolor="#8D8DEF">

                <input name="txtMI" type="text" size="2" maxlength="1">

                  

              </td>

          <td width="8%">(Last)</td>

          <td width="47%" bgcolor="#8D8DEF">

              <input name="txtLName" type="text" size="30" maxlength="30">

              

              </td>

        </tr>

      </table>       

          <br>

            <!-- The Submit Button should take us to the Validation.php file -->

        <div align="center"> <input type="submit" name="SubmitA1" value="Submit My Application Step 1">

         &nbsp;

         <!-- the reset button should clear everything and redisplay the current page only. -->

       <input type="reset" name="StartOver" value="Start Over">

         &nbsp;&nbsp;

       <!-- // The cancel button should take the user back to the beginning page I think. -->

         <input type="submit" name="Cancel" value="Cancel">

        </div>

    </form>       

   

   

   </td>

  </tr>

</table>

  </body>

</html>

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:OldHatt45
Comment Utility
Hey Fooky,
I agree my code was a bit messed up ;-))
Went through the code in your example and it does accomplish the first part of the answer to my problem, which is getting the Age information etc. populated.  
The only problem is that the List box display value keeps getting reset to "Future" after you select a different option.  I'm not sure what's going on with that.  

Second problem, is that when I come into firstpage.php the user can come in with the SESSION values set or not set depending on their entry point from previous page or menu selection.  That's why you saw these 4 lines at the top of firstpage.php
 // $_SESSION['AMDIDNo'] = '10272007-1';
      // $_SESSION['AMDName'] = 'Gracie';
      $_SESSION['AMDIDNo'] = NULL;
      $_SESSION['AMDName'] = NULL;
When they come in with "NULL" then I give them the list box.  When they come in with values I don't use the list box, I just give them a text box or text entry and automatically do the query to get the age.

Next, even after I refresh the browser session, the previous values selected remain visible, this could be my browser, but I'm not 100% sure.  I'll try it on another machine.

Next, I do not understand your comment about the First Name, MI and the session variables.  Yes I do want to set them as Session Variables.  I need them in other places.  I'm not sure where to put the code you showed that I copied below.

"If you need to set txtFName , txtMI etc. as session variables then change second form action to FirstPage.php and then on begining add "
if(isset($_POST['SubmitA1']){
$_SESSION['varName'] = $_POST['varName'];
header('Location: http://adress_to_my_site/frmAdt1.php');

Last problem with the example you gave.  If I start filling in the First Name and then go back and select a different option from the list box (which I have to allow) the First Name, MI, etc.  gets cleared out and returned to "  ".  I suspect I need something to grab the SESSION Variables and repopulate the filled in fields.  But not sure????  Maybe use _REQUEST ????????

Sorry to be a pain.  It will be worth your while for the extra help.

Thanks
OldHatt45
0
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
Almost done :)
First code then comment.
<?php

 require_once('ARD_fns.php');

      require_once('Connections/ARDMSQL1.php');

      session_start();

      

    

    if(isset($_POST['Cancel']){

      header('Location: http://myweb.com/Home.html');//change this to correct address

    }

    

    if(isset($_POST['SubmitA1']){ 

      $_SESSION['FName'] = $_POST['txtFName']; //change this to what you need (session names)

      $_SESSION['LName'] = $_POST['txtLName'];

      $_SESSION['MI'] = $_POST['txtMI'];

      header('Location: http://myweb.com/Adt1Proc.php'); //change this to correct address

    }

      

// DATA for List BOX

            mysql_select_db($database_ARDMSQL,$ARDMSQL1 );

            if ( ! $ARDMSQL1) {

                 die( "Couldn't connect to MySQL:  ".mysql.error() );

            }

            

            $query_rsDAMe = "SELECT ARDnumber, DName FROM Dots WHERE Disposition = 'f' || Disposition = 'r' ORDER BY DName ";

            $rsLB = mysql_query($query_rsDAMe, $ARDMSQL1)  or die(mysql_error());

            $totalRows_rsLB = mysql_num_rows($rsLB);

 
 

 

if(isset($_REQUEST['selectedD']){ // User selected someting else then Future = 111111111

  $_SESSION['AMDIDNo'] = $_REQUEST['selectedD'];

  

  //Get Age 

      mysql_select_db($database_ARDMSQL,$ARDMSQL1 );

           if ( ! $ARDMSQL1) {

                     die( "Couldn't connect to MySQL:  ".mysql.error() );

            }

      $query_rsDAMe = "SELECT ARDnumber, DName, DAgeYrs, DAgeMos FROM Dots WHERE ARDnumber = '" .$_SESSION['AMDIDNo']."'" ;

 

      $rsDAMe = mysql_query($query_rsDAMe, $ARDMSQL1 ) or die(mysql_error());

                      $row_rsDAMe = mysql_fetch_assoc($rsDAMe);

       $totalRows_rsDAMe = mysql_num_rows($rsDAMe);

      if ($totalRows_rsDAMe > 0) {

            $_SESSION['AMDName'] = $row_rsDAMe['DName'] ;

            $_SESSION['DAMYears'] = $row_rsDAMe['DAgeYrs'];

            $_SESSION['DAMMos'] = $row_rsDAMe['DAgeMos'];

      } else {

            $_SESSION['AMDName'] = NULL ;

            $_SESSION['DAMYears'] = NULL ;

            $_SESSION['DAMMos'] = NULL ;         

      }  

}

 

?>

 

 

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

  <meta http-equiv="content-type" content="text/html; charset=windows-1250">

  <meta name="generator" content="PSPad editor, www.pspad.com">

  <title></title>

  </head>

  <body>

  <table width="100%" height="162" border="0">

  <tr>

    <th width="15%" valign="top" bgcolor="#8D8DEF" scope="row">      <p>

<a href="http://aldr/index.htm"><img src="/images32/buttonhome.JPG" alt="" name="ButtonHome" width="137" height="30" vspace="5" border="0"></a>      

<a href="http://aldr/FirstPage.php"><img src="/images32/buttonAdt.JPG" alt="" name="ButtonAdt" width="137" height="30" vspace="5" border=0>

    <p>&nbsp;</p></th>

    <td width="85%" valign="top" bgcolor="#8D8DEF">

        &nbsp; <h1 align="center" class="style4">Some Introductory Information </h1>

      <p align="left" class="style6">Filling in the information requested below,  is the first step in the process. </p>

      <form action="FirstPage.php" method="post" >

        <table width="100%"  border="0" cellspacing="3" cellpadding="3">

          <tr>

           <th width="7%" scope="row">Name:</th>

           <td width="25%" bgcolor="#8D8DEF">

              

                  <select name="selectedD" size="1" style="width:275" onchange='this.form.submit()'>

                    <option value="11111111"> Future </option>

                <?php      

                  while ($row_rsLB = mysql_fetch_assoc($rsLB)) {

                ?>

                <!-- There was space before < ? php in value="" thats way it wasnt working  -->

                    <option  value="<?php echo $row_rsLB['ARDnumber']; ?>" <?php if($_SESSION['AMDIDNo'] == $row_rsLB['ARDnumber']) echo "selected" ?> > 

                      <?php echo $row_rsLB['Name']; ?> 

                    </option> 

                <?php

                  }

                ?>

                  </select> 

            </td>

          </tr>

          <tr>

            <td width="13%">Age (Approx): </td>

            <td width="24%" bgcolor="#8D8DEF">&nbsp;

              <?php 

                echo @$_SESSION['DAMYears'] 

              ?>

            </td>

          </tr>

          <tr>

            <td width="13%">Age Mos (Approx): </td>

            <td width="24%" bgcolor="#8D8DEF">&nbsp;

              <?php

                echo @$_SESSION['DAMMos'];

              ?>

            </td>

          </tr>

          <tr>

            <td colspan="2">

              <input type="submit" name="action" value="Select">

            </td>

          </tr>

        </table>

       <p align="left" class="style4">Person Information:&nbsp; 

         <input type="hidden" name="AIDNo" value="<?php print $ADRAID ?>" />  </p>

        <table width="72%"  border="0" cellspacing="3" cellpadding="3">

        <tr>

          <th width="7%" scope="row"><div align="left">Name:</div></th>

          <td width="7%">(First)</td>

          <td width="22%" bgcolor="#8D8DEF">

            <input name="txtFName" type="text" id="txtFName" size="25" maxlength="25"

            value="<?php echo @$_REQUEST['txtFName'] ?>">     

          </td>

          <td width="6%">(M.I.)</td>

          <td width="3%" bgcolor="#8D8DEF">

                <input name="txtMI" type="text" size="2" maxlength="1"

                value="<?php echo @$_REQUEST['txtMI'] ?>">

              </td>

          <td width="8%">(Last)</td>

          <td width="47%" bgcolor="#8D8DEF">

              <input name="txtLName" type="text" size="30" maxlength="30" 

                value="<?php echo @$_REQUEST['txtLName'] ?>">

              </td>

        </tr>

      </table>       

          <br>

            <!-- The Submit Button should take us to the Validation.php file -->

        <div align="center"> <input type="submit" name="SubmitA1" value="Submit My Application Step 1">

         &nbsp;

         <!-- the reset button should clear everything and redisplay the current page only. -->

       <input type="reset" name="StartOver" value="Start Over">

         &nbsp;&nbsp;

       <!-- // The cancel button should take the user back to the beginning page I think. -->

         <input type="submit" name="Cancel" value="Cancel">

        </div>

    </form>       

   

   

   </td>

  </tr>

</table>

  </body>

</html>

Open in new window

0
 
LVL 11

Accepted Solution

by:
f_o_o_k_y earned 500 total points
Comment Utility
Sorry for mistakes but I cannot debug this code (have no database or data).
1.
Last problem with the example you gave.  If I start filling in the First Name and then go back and select a different option from the list box (which I have to allow) the First Name, MI, etc.  gets cleared out and returned to "  ".
--
Should be ok now.  I changed it to one form and added value to rest of fields

2.
Yes I do want to set them as Session Variables
--
Ok. Lines 11 - 16

3.
Next, even after I refresh the browser session, the previous values selected remain visible, this could be my browser, but I'm not 100% sure.  I'll try it on another machine.
--
I do not understand. ??? Try to close and open browser again. Or explain me what is wrong?

4.
The only problem is that the List box display value keeps getting reset to "Future" after you select a different option.  I'm not sure what's going on with that.  
--
Mistype line 87.

5.
Second problem, is that when I come into firstpage.php the user can come in with the SESSION values set or not set depending on their entry point from previous page or menu selection.
--
Correct me if I'm wrong.
A) User has nothin :
  $_SESSION['AMDIDNo'] = NULL;
  $_SESSION['AMDName'] = NULL;

You are showing List box , and Person information.
B) User has already
   $_SESSION['AMDIDNo'] = '10272007-1';
    $_SESSION['AMDName'] = 'Gracie';
We are showing age, age mos, personal information (but we are  not showing Listbox)?
Do we have to query
 "SELECT ARDnumber, DName, DAgeYrs, DAgeMos FROM Dots WHERE ARDnumber = '" .$_SESSION['AMDIDNo']. "' AND DName = '" .$_SESSION['AMDName']."'";
or we can use
 "SELECT ARDnumber, DName, DAgeYrs, DAgeMos FROM Dots WHERE ARDnumber = '" .$_SESSION['AMDIDNo']. "'
???
should we use  $_SESSION['AMDName'] somewhere in this form??

C) is there any other case?

0
 

Author Comment

by:OldHatt45
Comment Utility
Hi Fooky,
Well I looked at the latest code you wrote.  And in answer to your items above (MY COMMENTS ARE ALL IN CAPS SO IT'S EASY TO SEE):
1.
Last problem with the example you gave.  If I start filling in the First Name and then go back and select a different option from the list box (which I have to allow) the First Name, MI, etc.  gets cleared out and returned to "  ".
--
Should be ok now.  I changed it to one form and added value to rest of fields
*******  THIS WORKS AND IS GOOD! *****************

2.
Yes I do want to set them as Session Variables
--
Ok. Lines 11 - 16
*************  AGAIN, THIS WORKS AND IS GOOD ***************************

3.
Next, even after I refresh the browser session, the previous values selected remain visible, this could be my browser, but I'm not 100% sure.  I'll try it on another machine.
--
I do not understand. ??? Try to close and open browser again. Or explain me what is wrong?
***************  DON'T WORRY, I FIGURED OUT WHAT WAS WRONG **************************
*************** SO THIS ONE IS FIXED ****************************************************************
4.
The only problem is that the List box display value keeps getting reset to "Future" after you select a different option.  I'm not sure what's going on with that.  
--
Mistype line 87.
************************  IT'S NOT LINE 87 **************************************
******* I DID AS YOU SAID AND FIXED LINE 87 AND IT STILL DOES THE SAME THING ***************
5.
Second problem, is that when I come into firstpage.php the user can come in with the SESSION values set or not set depending on their entry point from previous page or menu selection.
************************* The ONLY 2 CASES ARE THE USER COMES INTO THE PAGE WITH THE 2 SESSION VARIABLES SET OR THEY COME IN WITHOUT THE 2 VARIABLES SET.  i FIGURED OUT HOW TO DO THIS BY USING A VARIABLE THAT I SET WHEN THE USER COMES INTO THE PAGE.  I USE THE $UseLB VARIABLE AND PUT THIS CODE IN RIGHT AFTER THE LIST BOX CODE ON LINE 28 OF YOUR EXAMPLE
if ( !isset($_SESSION['AMDobeIDNo'])) {
      $_SESSION['AMDobeIDNo'] = "11111111";
      $UseLB = true ;
        echo $_SESSION['AMDobeName'];
} else {
    $UseLB = false ;
        echo $_SESSION['AMDobeName'];
}      
THE ECHO STATEMENTS ARE FOR TESTING.

 5.  Second problem, is that when I come into firstpage.php the user can come in with the SESSION values set or not set depending on their entry point from previous page or menu selection.

****** YOU GOT IT EXACTLY RIGHT.  THOSE ARE THE ONLY 2 CASES.
fOR THE B ANSWER I USED THE 2ND QUERY:
 "SELECT ARDnumber, DName, DAgeYrs, DAgeMos FROM Dots WHERE ARDnumber = '" .$_SESSION['AMDIDNo']. "'
AND YES WE DO NEED TO SAVE THE AMDName in the SESSION VARIABLE, SO IT'S AVAILABLE.
--

==================================================

Now the last remaining piece of the puzzle.

I wrote a DummyProc.php page:
<?php
 session_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<?php echo "This is the Adt 1 Processing page " ;
       echo $_SESSION['AMDName'] ;
       echo $_SESSION['AMDIDNo']  ;
       echo $_SESSION['AMYears'] ;
       echo $_SESSION['AMMos'] ;
       echo $_SESSION['AMAID'] ;
       echo $_SESSION['AFname'] ;
       echo $_SESSION['AMInit'] ;      
       echo $_SESSION['AMLname'] ;
?>
</body>
</html>
***************************** End of Page ****************************
WHen I run the FirstPage.php and hit the sumit button I get the right results when I came in with NO List box.  When I use the List box, I get
This is the Adt 1 Processing page 11111111ADR20071206124015MyFirstsMyLast

Everythin after the "11111111" is from the LINE 119 DOWN in your example.  I get nothing before that.  Oh, and this output is where I actually selected Gracie and her number from the list box.

If we get these couple of things fixed, it would be very very GOOD

Thanks

OldHatt45
0
 
LVL 11

Expert Comment

by:f_o_o_k_y
Comment Utility
Last problem might be because ListBox is not wirking properly.

I need you to go to the FirstPage.php Select something from ListBox. (then autocommit should fill Age filds) then right click somewhere and select VIEW PAGE SOURCE.
I need to see what is generated in the ListBOx.

I also need more description about error on the dummyProc.php
Which walues are correct and which are not and when.

You wrote 11111111ADR20071206124015MyFirstsMyLast  and this tells me nothing because I'dont know what shloud be in there.

Try to describe what you are doing.
For example I'm getting to the first page without any session data stored. I select something form list box.
Then enter FNam = 'MyName' etc.
And When I click submit I'm getting this and this but I should get this and this

Try to put 'varName' and <br /> in dummyProc.php that I will be able to see which value is for what var.
example below:


<?php

 session_start();

?>
 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Untitled Document</title>

</head>
 

<body>

<?php echo "This is the Adt 1 Processing page " ;

       echo 'AMDName='.$_SESSION['AMDName'] .'<br />';

       echo 'AMDIDNo='. $_SESSION['AMDIDNo'] .'<br />' ;

       echo 'AMYears='.$_SESSION['AMYears'] .'<br />';

       echo 'AMMos='.$_SESSION['AMMos'].'<br />' ;

       echo 'AMAID='.$_SESSION['AMAID'] .'<br />';

       echo 'AFname='.$_SESSION['AFname'] .'<br />';

       echo 'AMInit='.$_SESSION['AMInit'] .'<br />';      

       echo 'AMLname='.$_SESSION['AMLname'] .'<br />';

?>

</body>

</html>

Open in new window

0
 

Author Comment

by:OldHatt45
Comment Utility
Fooky,

Sorry, sometimes I forget that yu don't know everything I know about what I'm doing ;-))

Here is the relevant section of the VIEW SOURCE Before Selecting anything from the List Box.
       <form action="Adt1.php" method="post" >  
        <table width="100%"  border="0" cellspacing="3" cellpadding="3">
        <tr>
          <th width="7%" scope="row">Name:</th>
        <!-- Here we need to set up the list box or just a plain text field depending on where they came from. -->
          <!-- So an if statement where we check the came from will determine what happens. -->
          <td width="25%" bgcolor="#8D8DEF">
                                          <select name="selectedD" size="1" style="width:275" onChange='this.form.submit()'>
                              <option value="11111111" selected>Future</option>
                                                            <option value="12032007-1">Cody</option>
                                                            <option value="10282007-1">Ellie</option>
                                                            <option value="10272007-1">Gracie</option>
                                                    </select>
                                  </td>
          <td width="13%">Age (Approx): </td>
          <td width="24%" bgcolor="#8D8DEF">&nbsp;
                   year(s) and  months old                     
              </td>
          <td width="4%">Sex:</td>
          <td width="27%" bgcolor="#8D8DEF">&nbsp;
                                     </td>
        </tr>
/*********************************** End of First View SOURCE ************************************************/

Then I select Gracie  and here is the same section of the SOurce from after the selection

       <form action="Adt1.php" method="post" >  
        <table width="100%"  border="0" cellspacing="3" cellpadding="3">
        <tr>
          <th width="7%" scope="row">Name:</th>
        <!-- Here we need to set up the list box or just a plain text field depending on where they came from. -->
          <!-- So an if statement where we check the came from will determine what happens. -->
          <td width="25%" bgcolor="#8D8DEF">
                            </td>
          <td width="13%">Age (Approx): </td>
          <td width="24%" bgcolor="#8D8DEF">&nbsp;
                  1 year(s) and 6 months old                     
              </td>

/********************************** End of Second View SOURCE ********************************************/

/********************************* Output from DUmmyProc1 ************************************************/
This is the Adt 1 Processing page                      /************* THis is First echo

/******************************* End of Output from DUmmyProc1.php ************************************/

I started the page in a separate browser window.
In the page I commented out all 4 starting SESSION Variables, so that there would be nothing in the way.
When I got to the page, I had the list box.  I clicked on the text box and got the list.
I then Clicked on "Gracie" on the page I gt her Age (both Months and Years.)  I did not get her Name back in the list box.  I got "Future"  in the List Box.  
I then filled in the FIrst Middle and Last Name and clicked on submit.

THat's it.  That's all I did.

THanks

OldHatt45

0
 

Author Comment

by:OldHatt45
Comment Utility
Is there anyone out there that can help finish this????
I really need to get this going and the attempted solutins are not working.

I would really appreciate some additional input

OldHatt45
0
 

Author Closing Comment

by:OldHatt45
Comment Utility
Since this "question" was only partially answered, I have done as the Zone Advisor suggested.  Mark it as partial and award points as "Good".
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
spacing 5 24
PHP question(s) about order of output 9 38
creating 2 user ID's 5 24
Codiing Non-Existent Links 4 21
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now