0
<form action="action.php" method="POST"  target="_self">
<table class="main"  border="1"  height="100%" align="center">
<h3>
<p id="id1" style="background-color: #9FF" >Registration form</p></h3>

 <tr><td> First Name:<span style="color:red">*</span> </td> 
<td> <input type="text"  name="fname" value="" placeholder="firstname"    required="required" maxlength="25"></td></tr>
 <tr><td> SurName:<span style="color:red">*</span></td> 
 <td><input type="text"  name="sname" value=""  placeholder="lastname" required="required" maxlength="20"/> </td></tr>
 <tr><td>Age:<span style="color:red">*</span></td>
 <td> <input type="text" name="age" value="" required/></td></tr>
 <tr><td>Date of Birth:<span style="color:red">*</span></td>
 <td><input type="date" name="DOB" value="" required/></td></tr>
 <tr><td> Gender:<span style="color:red">*</span></td>
  <td><input type="radio" name="gender" value="male" required/>Male 
   <input type="radio" name="gender" value="Female" />Female</td></tr>
  <tr><td>Qualification:<span style="color:red">*</span></td>
   <td> <select name="study" required>
   <option value="">---Select---</option>
  <option value="btech">B.Tech</option>
  <option value="BSc">BSc</option>
  <option value="BCom">BCom</option>
 </select></td></tr>
  <tr><td> State:<span style="color:red">*</span></td>
<td><Select name="state" required >
<option value="">---Select---</option>
<option valuie="AndhraPradesh">AndhraPradesh</option>
<option value="Telangana">Telangana</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Kerala">Kerala</option>
<option vgalue="Maharastra">Maharastra</option>
</Select></td></tr> 

<tr><td>Profile:<span style="color:red">*</span></td><td><input type="checkbox" name="profile" value="Java" />Java
                            <input type="checkbox" name="profile" value="PHP" />PHP
                            <input type="checkbox" name="profile" val

    ue="Android" />Android</td> </tr>
    <tr><td> Address for Communication:</td><td><textarea name="adr" rows="5" cols="30" ></textarea></td></tr>
            <tr><td colspan="2" align="center"><input type="submit" value="submit" /></td></tr>                  
    </table></form>

** this is my register form and now i want to display all the selected values in next page i.e in action.php and its code is as follows********

    <form action="store.php" method="post" align="center" target="_self">
    <label>Name of the person:</label> 
   <input type="hidden" name="person" value="<?= $_POST['fname'];?>"></input><?=$_POST['fname'];?>  <br />
    <label>Name of the Surname:</label>
    <input type="hidden" name="surname" value="<?= $_POST['sname'];?>"></input><?=$_POST['sname'];?>  <br />
    <label>His Age:</label>
     <input type="hidden" name="age" value="<?= $_POST['age'];?>"></input><?=$_POST['age'];?> <br />
     <label>Date of Birth:</label>
     <input type="hidden" name="dob" value="<$_POST['DOB'];?>"></input><?=$_POST['DOB'];?>  <br />
      <label>Gender:</label> 
     <input type="hidden" name="gender" value="<?= $_POST['gender'];?>"></input><?=$_POST['gender'];?> <br />
      <label>Education:</label> 
     <input type="hidden" name="edu" value="<?php if(isset($_POST['submit']))echo $_POST['study']?>"></input><?php if(isset($_POST['submit'])) echo $_POST['study']?>;?> 
      <br />
      <label>State:</label>
      <input type="hidden" name="state" value="<?if(isset($_POST['submit']))echo $_POST['state']?>"></input><?php if(isset($_POST['submit'])) echo $_POST['state']?>;?> 
      <br />
      <label>Good At:</label>
     <input type="hidden" name="profile" value="<?= $_POST['profile'];?>"></input><?=$_POST['profile'];?>  <br />
      <label>Address:</label>
      <input type="hidden" name="adr" value="<?= $_POST['adr'];?>"></input><?=$_POST['adr'];?>  <br /><br /><br />
      <input type="submit" value="confirm" name="submit"></input>

****the dropdown is not displaying and also please suggest if after click on confirm then the values that are confirmed has to be stored in database.For that shall I get the values from names of input hidden fields in action.php or registration input field names?

3 Answers3

1
  1. There's a lot of syntax errors in your code.
  2. You haven't added a name attribute in the submit button. There should be name="submit" in it. Otherwise when displaying the drop down values, it is being check in your code, and it wouldn't be displayed (because no variable named submit was found in the $_POST array).
  3. The check box is using the same name. So it should be an array. use name=profile[] instead of name=profile

Finally form.php should look like this:

<form action="action.php" method="POST"  target="_self">
<table class="main"  border="1"  height="100%" align="center">
<h3>
<p id="id1" style="background-color: #9FF" >Registration form</p></h3>

 <tr><td> First Name:<span style="color:red">*</span> </td> 
<td> <input type="text"  name="fname" value="" placeholder="firstname"    required="required" maxlength="25"></td></tr>
 <tr><td> SurName:<span style="color:red">*</span></td> 
 <td><input type="text"  name="sname" value=""  placeholder="lastname" required="required" maxlength="20"/> </td></tr>
 <tr><td>Age:<span style="color:red">*</span></td>
 <td> <input type="text" name="age" value="" required/></td></tr>
 <tr><td>Date of Birth:<span style="color:red">*</span></td>
 <td><input type="date" name="DOB" value="" required/></td></tr>
 <tr><td> Gender:<span style="color:red">*</span></td>
  <td><input type="radio" name="gender" value="male" required/>Male 
   <input type="radio" name="gender" value="Female" />Female</td></tr>
  <tr><td>Qualification:<span style="color:red">*</span></td>
   <td> <select name="study" required>
   <option value="">---Select---</option>
  <option value="btech">B.Tech</option>
  <option value="BSc">BSc</option>
  <option value="BCom">BCom</option>
 </select></td></tr>
  <tr><td> State:<span style="color:red">*</span></td>
<td><Select name="state" required >
<option value="">---Select---</option>
<option value="AndhraPradesh">AndhraPradesh</option>
<option value="Telangana">Telangana</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Kerala">Kerala</option>
<option vgalue="Maharastra">Maharastra</option>
</Select></td></tr> 

<tr><td>Profile:<span style="color:red">*</span></td><td>

                <input type="checkbox" name="profile[]" value="Java" />Java
                            <input type="checkbox" name="profile[]" value="PHP" />PHP
                            <input type="checkbox" name="profile[]" value="Android" />Android</td> </tr>
    <tr><td> Address for Communication:</td><td><textarea name="adr" rows="5" cols="30" ></textarea></td></tr>
            <tr><td colspan="2" align="center"><input type="submit" name="submit" value="submit" /></td></tr>                  
    </table></form>

And the action.php should be like this:

<form action="store.php" method="post" align="center" target="_self">
    <label>Name of the person:</label> 
   <input type="hidden" name="person" value="<?= $_POST['fname'];?>"></input><?=$_POST['fname'];?>  <br />
    <label>Name of the Surname:</label>
    <input type="hidden" name="surname" value="<?= $_POST['sname'];?>"></input><?=$_POST['sname'];?>  <br />
    <label>His Age:</label>
     <input type="hidden" name="age" value="<?= $_POST['age'];?>"></input><?=$_POST['age'];?> <br />
     <label>Date of Birth:</label>
     <input type="hidden" name="dob" value="<$_POST['DOB'];?>"></input><?=$_POST['DOB'];?>  <br />
      <label>Gender:</label> 
     <input type="hidden" name="gender" value="<?= $_POST['gender'];?>"></input><?=$_POST['gender'];?> <br />
      <label>Education:</label> 
     <input type="hidden" name="edu" value="<?php if(isset($_POST['submit'])) echo $_POST['study'];?>"></input><?php if(isset($_POST['submit'])) echo $_POST['study'];?> 
      <br />
      <label>State:</label>
      <input type="hidden" name="state" value="<?if(isset($_POST['submit'])) echo $_POST['state'];?>"></input><?php if(isset($_POST['submit'])) echo $_POST['state'];?> 
      <br />
      <label>Good At:</label>
     <input type="hidden" name="profile" value="<?php echo implode(", ", $_POST['profile']); ?>">
<?php 
echo implode(", ", $_POST['profile']);
//print_r($_POST['profile']);
 ?>  

<br />
      <label>Address:</label>
      <input type="hidden" name="adr" value="<?= $_POST['adr'];?>"></input><?=$_POST['adr'];?>  <br /><br /><br />
      <input type="submit" value="confirm" name="submit"></input>

The data which you are going to store in the database, depends on your database design.

E.g.:- It depends on whether you are going to store the check box values as a comma separated string or, using a different table.

Any how at this point of your program, once you are in the action.php page, the data which you fetched using the registration form, could be sent to store.php using a session. Otherwise in the store.php if you use $_POST you'll get the input values which are in those hidden input fields of the action.php page.

Anjana
  • 462
  • 2
  • 14
0

I have changed a bit of the code... You had some minor syntax mistakes...

 <form action="store.php" method="post" align="center" target="_self">
    <label>Name of the person:</label> 
   <input type="hidden" name="person" value="<?= $_POST['fname'];?>"></input><?=$_POST['fname'];?>  <br />
    <label>Name of the Surname:</label>
    <input type="hidden" name="surname" value="<?= $_POST['sname'];?>"></input><?=$_POST['sname'];?>  <br />
    <label>His Age:</label>
     <input type="hidden" name="age" value="<?= $_POST['age'];?>"></input><?=$_POST['age'];?> <br />
     <label>Date of Birth:</label>
     <input type="hidden" name="dob" value="<$_POST['DOB'];?>"></input><?=$_POST['DOB'];?>  <br />
      <label>Gender:</label> 
     <input type="hidden" name="gender" value="<?= $_POST['gender'];?>"></input><?=$_POST['gender'];?> <br />
      <label>Education:</label> 
     <input type="hidden" name="edu" value="<?php echo $_POST['study']; ?>"></input><?php echo $_POST['study'];?> 
      <br />
      <label>State:</label>
      <input type="hidden" name="state" value="<?php echo $_POST['state'];?>"></input><?php  echo $_POST['state'];?> 
      <br />
      <label>Good At:</label>
     <input type="hidden" name="profile" value="<?= $_POST['profile'];?>"></input><?=$_POST['profile'];?>  <br />
      <label>Address:</label>
      <input type="hidden" name="adr" value="<?= $_POST['adr'];?>"></input><?=$_POST['adr'];?>  <br /><br /><br />
      <input type="submit" value="confirm" name="submit"></input>
Jegadesh B S
  • 689
  • 1
  • 6
  • 14
0
    <SELECT name="abc">
<option value="option1" selected> This is option 1 </option>
<option value="option2"> This is option 2 </option>
</SELECT>

and php get the value of $_POST['abc'] is option1 when submitted the post