Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8440707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:21:51+00:00 2026-06-10T08:21:51+00:00

I have a form on one page, and the submit button on that page

  • 0

I have a form on one page, and the submit button on that page leads the user to the next page of the form. I’m trying to set it up so that the info from form 1 is submitted along with form 2’s info when the submit button on form 2 is clicked and all forms have been filled out, however, the first form’s data is being submitted to my database when proceeding to form 2. Any ideas why this is the case? And any ideas of a solution?

Also, I am getting an error “undefined index GET” from the first form and I am struggling to understand why?

Thanks in advance!

Form 1 (parent.php)

<?php session_start(); 
$_SESSION['fName']=$GET['fName'];
$_SESSION['sName']=$GET['sName'];
$_SESSION['email']=$GET['email'];
$_SESSION['address']=$GET['address'];


?>


<!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>table2</title>
</head>
<h1>Is this in xamppfiles and htdocs?</h1>




<form action="child2.php" method="post" class="validate">
<div>
<input class="tb" type="text" name="fName" placeholder="first name" id="fName" value=" <?php $fName ?>" required/><br/>
 <br/>
  <input class="tb" type="text" name="sName" placeholder="surname" id="sName" value="<?php $sName ?>" required/><br/>
  <br/>
  <input class="tb" type="email" name="email" required placeholder="email address" id="email" value="<?php $email ?>" required/>
  <br/>
  <input class="tb" type="address" name="address" placeholder="address" value="<?php $address ?>" id="address" />
  <br/>


  <input id="submit" name="submit" type="submit" value="Next">
  </div>
  </form> 




</body>
</html>

Form 2 (child2.php)

 <?php
  session_start();
  include("connect.php");
 ?>
<!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>table2</title>
</head>

<body>


 <?php
function renderForm($fName, $sName, $email, $address){ 
?>



<form action="" method="post" class="validate">

<label class="label">first name</label><input class="tb" type="text" id="fName"     name="fName" value="<?php if (isset($fName)) { echo $fName = $_SESSION['fName'];} else {    if(!isset($fName)) { echo ""; }}?>"/> 
</br>
<label class="label">surname</label><input class="tb" type="text" id="sName"  name="sName" value="<?php if (isset($sName)) { echo $sName = $_SESSION['sName'];} else {  if(!isset($sName)) { echo ""; }}?>"/>
</br>
<label class="label">email</label><input class="tb" type="email" id="email"  name="email" value="<?php if (isset($email)) { echo $email = $_SESSION['email'];} else { if(!isset($email)) { echo ""; }}?>""/>
</br>
<label class="label">address</label><input class="tb" type="text" id="address"  name="address" value="<?php if (isset($address)) { echo $address = $_SESSION['address'];}    else { if(!isset($address)) { echo ""; }}?>""/>
</br>

<input id="submit" type="submit" value="Submit"/>
</form>

<?php
}


// check if the form has been submitted. If it has, start to process the form and save it to the database
  if (isset($_POST['submit']))
 { 
 // get form data, making sure it is valid
 $fName = mysql_real_escape_string(htmlspecialchars($_POST['fName']));
 $sName = mysql_real_escape_string(htmlspecialchars($_POST['sName']));
 $email = mysql_real_escape_string(htmlspecialchars($_POST['email']));
 $address = mysql_real_escape_string(htmlspecialchars($_POST['address']));

 // check to make sure both fields are entered
 if ($fName == '' || $sName == '' || $email == '')
 {
 // generate error message
 $error = 'ERROR: Please fill in all required fields!';

 // if either field is blank, display the form again
 renderForm($fName, $sName, $email, $address, $error);
 }
 else
 {
 // save the data to the database
 mysql_query("INSERT formtest SET fName='$fName', sName='$sName',email='$email', address='$address'")
 or die(mysql_error()); 

 // once saved, redirect back to the view page
 header("Location: child2.php"); 
 }
 }
 else
 // if the form hasn't been submitted, display the form
 {
 renderForm('','','','','');
 }

?>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:21:52+00:00Added an answer on June 10, 2026 at 8:21 am

    The action field of your parent.php is child2.php . Also, you are checking for

    if (isset($_POST['submit']))
    

    which is set true by your first page, hence, it goes inside the loop and inserts the data in your database. This can be resolved by placing this in your parent file

      <input id="submit" name="submitINIT" type="submit" value="Next">
    

    A possible solution can be, you extract the values of the first form and store it in some session variables , and finally at final submission, you can use those values for insertion.

    In your child2.php, do this

     if (isset($_POST['submitINIT'])){
       // store all the available values in some session variables
    $_SESSION['value1']=$POST['fName'];
    $_SESSION['value2']=$POST['sName'];
    $_SESSION['value3']=$POST['email'];
    $_SESSION['value4']=$POST['address'];
    }
    
     if (isset($_POST['submit'])){
       // proceed after final submission
    }
    

    Also, change the action of 2nd file to itself using this

    <form action="child2.php" method="post" class="validate">
    

    Also, do this modification in your child2.php

    <input id="submit" name="submit" type="submit" value="Submit"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On a page that I'm designing I have a form with one input of
I have one form in JSP. I have some input fields in that page,
I have 3 portals on the view (one form) with one submit button. I
I have a simple form with just one textbox and one submit button. The
I have a simple form with one hidden input field, and a submit button.
I have a form on an HTML page with multiple submit buttons that perform
I have a simple page with one textfield and a submit button. I want
I have 3 elements and one form with a button: <input type=submit value=Follow All
I have a page where there is currently more than one form. I used
I have one form with several text fields and one button. When i enter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.