I am fairly new to PHP, but have applied my previous knowledge of programming, along with internet searches to get me this far.
I'm trying to make a step by step form entry, where the criteria entered on a page by page basis and only updates the database once the entire form is filled out. I plan on embellishing the form further after I get the basic functionality working on it.
As of the moment the name variable is getting populated, however after submission of the second stage it loops back to the first stage of entry, although the URL updates to stage 3, because of this the information can not get parsed to the database.
I am using PHP v5, I have seen resolutions to this issue using AJAX, but I am not using it in this instance.
Thank you for your time and efforts.
<?php
$stage = $_GET['stage'];
//Starting on form 1
$stage = 'one';
//get form details
$name = $_POST['name'];
$surname = $_POST['surname'];
/* ---- Checking if you submitted and if you were on form one THEN set the form the stage2 in order to display the next form ---- */
if (isset($_POST['submitStage1']) && $stage == 'one') {
$stage = 'two';
echo "checking sumbit from stage1";
}
if (isset($_POST['submitStage2']) && $stage == 'two') {
$stage = 'three';
echo "checking submit from stage2 going to 3";
}
if (isset($_POST['submitStage3']) && $stage == 'three') {
$stage = 'three';
echo "Adding to database";
}
?>
<?php
if ($stage == 'one') {
echo $stage;
?>
<div style="width:100%; margin-bottom: 20px;"> Step_001</div>
<form method="post" action="addperson.php?stage=2">
<input name="name" type="text" />
<input name="submitStage1" type="submit" />
</form>
<?php
}
?>
<?php
if ($stage == 'two') {
echo $stage;
?>
<div style="width:100%; margin-bottom: 20px;"> Step_002</div>
<form method="post" action="addperson.php?stage=3">
<input name="surname" type="text" />
<input name="submitStage2" type="submit" />
</form>
<?php
}
?>
<?php if ($stage == 'three') { echo $stage;
echo "Adding to database";
$name = mysql_real_escape_string($_POST['name']); $surname = mysql_real_escape_string($_POST['surname']);
// Add this product into the database now
$sql = mysql_query("INSERT INTO testpeople (name, surname)
VALUES('$name','$surname')") or die (mysql_error());
exit(); } ?>