Trying out some things with php and html, I'm having issues trying to get all of my form data reposted. I've figured out how to do the text boxes. Still at a loss for the select box, radio and check box. Would I be better off reposting inside the HTML page or letting my include template code take care of it?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/rocks.css">
<title>About Us-- Rocks</title>
</head>
<body>
<?php include("templates/banner_navigation.php"); ?>
<div id="links_group">
<?php include("templates/menu.php"); ?> <!-- 1st include for navigation, stored in templates -->
</div>
<div id="about_us_form">
<?php include("templates/about_us_valid.php"); ?>
<form action="<?php echo $PHP_SELF;?>" method="post">
<table>
<tr><td>First name:</td><td><input type="text" name="contact_name" title="Enter your first name here" value="<?php if (isset($_POST['contact_name'])) echo $_POST['contact_name']; ?>" /></td></tr>
<tr><td>Email Address:</td><td><input type="text" name="contact_email" title="Enter your email here" value="<?php if (isset($_POST['contact_email'])) echo $_POST['contact_email']; ?>" ></td></tr>
<tr><td>Phone Number:</td><td><input type="text" name="contact_phone_number" title="555-555-5555" value="<?php if (isset($_POST['contact_phone_number'])) echo $_POST['contact_phone_number']; ?>" /></td></tr>
<tr><td>I prefer to be contacted by:</td><td><input type="radio" name="preference" value="Email" checked/>Email<input type="radio" name="preference" value="Phone" />Phone</td></tr>
<tr><td>I am interested in:</td> <td><select name="select_rocks"><option value="gold">Gold</option>
<option value="silver">Silver</option>
<option value="thorium" selected="selected">Thorium</option>
<option value="titanium">Titanium</option>
</select></td></tr>
<tr><td> I would like to ask about:</td></tr>
<tr><td><textarea name="that_textarea" rows ="10" cols="25" title="Enter your questions here!">
</textarea></td></tr>
<tr><td>I am also interested in:</td><td>
<tr><td>Gemstones <input type="checkbox" name="checkbox1[]" value="gemstones" /></td><tr>
<tr><td>Ore processing <input type="checkbox" name="checkbox1[]" value="oreprocessing" /></td></tr>
<tr><td><input type="hidden" name="checkbox1[]" value="" /> </td><tr>
<tr><td><input type="submit" value="submit" name="submitform" /></td></tr>
</table><br/>
</form>
</div>
</body>
the include template:
<?php
function check_for_cat($namecheck=false,$emailcheck=false){
if ($namecheck) $name_field_error = "(((Name Invalid!)))";
if ($emailcheck) $email_field_error = "(((Email Invalid!)))";
//Start of form
if($namecheck) echo "<tr><td>$name_field_error</td></tr>";
if($emailcheck) echo "<tr><td>$email_field_error</td></tr>";
}
if (!isset($_POST['submitform'])) {
check_for_cat();
} else {
$namecheck = false;
$emailcheck = false;
$contact_name = isset($_POST['contact_name']) ? trim($_POST['contact_name']) : '';
$contact_email = isset($_POST['contact_email']) ? trim($_POST['contact_email']) : '';
if (strlen($contact_name)<3) $namecheck = true;
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) $emailcheck=true;
if ($namecheck || $emailcheck ){
check_for_cat($namecheck,$emailcheck);
} else {
echo '(((OMG the form is submitted!)))';
}
}
?>
Its probably pretty easy to do, I've just been looking at the code for too long, Thanks for the help! If possible put some code up, google and yahoo haven't found me much to look at.
For use Selected Option ...
Both radio and checkbox inputs with work with checked="checked" in order for them to be checked. You must use some php logic to determine if the user's input matches the necessary input to check the radio/checkbox and dropdown. For instance:
<input type="checkbox" <?php if ($userval == $boxval) echo 'checked="checked"'; ?> />
Related
Hopefully this makes sense. Been working on a project for awhile and i'm just about done! Just stuck and not sure why this isn't working.
I have an entire Crud app used with php and mysql. Everything works correctly except for when I go to my update.php page. When I click update on the home page, it takes me to the update page where I can fill out fields to update the mysql data. That all works fine! What I am having issues with is when I go to the update page, the form fields are blank. I want them to be pre-filled with the data that's already in there, so "fetching" the data. That way, the user doesn't have to go back and look at the data and then re-type all the information again instead of just backspacing and updating just the field data that they want. Does that make sense? Here's my code. Notice and focus where I have the $fetch variable...I know it's a lot. I tried to remove all the really unecessary stuff. If you are able to look at this and see an easy fix, please let me know! Struggling here. Below is my "update.php" page:
<?php
session_start();
$login_session=$_SESSION['login_user'];?>
<?php
if(!$_SESSION['login_user']){
header("location: login.php");
die;
}
?>
<p>Go Back |
Logout </p>
<?php
include 'scripts/db.php';
if(isset($_GET['id']) && is_numeric($_GET['id']))
{
$id=$_GET['id'];
}
$select=mysql_query("SELECT * FROM Order_1 WHERE id='$id'");
$fetch=mysql_fetch_array($select);
if(isset($_POST['update']))
{
$name=$_POST['name'];
$product=$_POST['product'];
$size=$_POST['size'];
$price=$_POST['price'];
$shipping=$_POST['shipping'];
$shipped=$_POST['shipped'];
$delivered=$_POST['delivered'];
$update=mysql_query("UPDATE Order_1 SET Name='$name',Product='$product',Size='$size',Price='$price',Shipping='$shipping',Shipped='$shipped',Delivered='$delivered' WHERE id='$id' ");
if($update) {
?>
<script>alert('Record updated successfully!');</script>
<?php
echo '<script type="text/javascript">window.location="home.php";</script>';
}
else
{
?>
<script>alert('Error updating record.');</script>
<?php
}
}
?>
<div class="container">
<h1>Edit Your Order and Click Submit:</h1>
<div class="updateForm">
<form method="post">
<p>Name: <input type="text" name="name" placeholder="First, Last" value="<?php echo $fetch['name']; ?>" /></p>
<p>Product: <input type="text" name="product" size="15" placeholder="T-Shirt, Shoes, etc..." value="<?php echo $fetch['product']; ?>" /></p>
<p>Size: <input type="text" name="size" size="10" placeholder="S, M, L, XL, XXL" value="<?php echo $fetch['size']; ?>" /></p>
<p>Price: <input type="text" name="price" size="10" placeholder="$0.00" value="<?php echo $fetch['price']; ?>" /></p>
<p>Shipping: <input type="text" name="shipping" size="10" placeholder="$0.00" value="<?php echo $fetch['shipping']; ?>" /></p>
<p>Shipped?
Yes<input type="radio" name = "shipped" value="Yes" value= "<?php echo $fetch['Yes']; ?>"/>
No<input type="radio" name = "shipped" value="No" value = "<?php echo $fetch['No']; ?>" /></p>
<p>Delivered?
Yes<input type="radio" name = "delivered" value="Yes" value="<?php echo $fetch['Yes']; ?>" />
No<input type="radio" name = "delivered" value = "<?php echo $fetch['No']; ?>" /></p>
<p><input type="submit" name="update" value="Submit" /></p>
</form>
</div>
</div>
I am new to coding and pardon me if it a silly thing I am missing. I have searched through the forum & did not find an answer that suits my need. I have 2 files: jobs.php & jobprocess.php
Jobs.php goes as
<?php session_start();
include('dbConnect.php');
$q1="abc";
$q2="pqr";
$q3="xyz";
$opportunity=29;
echo "Opportunity is". $opportunity;
?>
<html>
<head>
<div align="center">
<form method="post" method="post" action="jobprocess.php">
<input type="text" name="q1" placeholder="<?php echo $q1;?>"><br>
<input type="text" name="q2" placeholder="<?php echo $q2;?>"><br>
<input type="text" name="q3" placeholder="<?php echo $q3;?>"><br>
<input type="hidden" name="opportunity" value="<?php echo $opportunity;?>">
<ul class="actions">
<li><input type="submit" name="submit" value="I would like to join!! "></li>
</ul>
</form>
</div>
</head>
<body>
</body>
</html>
jobprocess.php goes with the code
<?php session_start();
include('dbConnect.php');
$opportunity = $_GET['opportunity'];
echo "opportunity is " . $opportunity;
?>
Unfortunately, the above code is not defining value="29" for opportunity on 2nd page. Thanks in advance
If you echo anything before the html tag it would effectively make the html invalid. Also, the head of the document MUST not have presentational html elements such as forms, divs etc
<?php
session_start();
include('dbConnect.php');
$q1="abc";
$q2="pqr";
$q3="xyz";
$opportunity=29;
?>
<html>
<head>
<title>must have a title</title>
</head>
<body>
<?php
echo "Opportunity is". $opportunity;
?>
<div align="center">
<form method="post" method="post" action="jobprocess.php">
<input type="text" name="q1" placeholder="<?php echo $q1;?>"><br>
<input type="text" name="q2" placeholder="<?php echo $q2;?>"><br>
<input type="text" name="q3" placeholder="<?php echo $q3;?>"><br>
<input type="hidden" name="opportunity" value="<?php echo $opportunity;?>">
<ul class="actions">
<li><input type="submit" name="submit" value="I would like to join!! "></li>
</ul>
</form>
</div>
</body>
</html>
And because the form is set to POST you should probably check and use the POSTed variable rather than a GET variable
<?php
session_start();
include('dbConnect.php');
$opportunity = $_POST['opportunity'];
echo "opportunity is " . $opportunity;
?>
Surprisingly my answer that suggested using session variable instead of hidden form field was deleted?! I guess session variables are illegal now?
The answer was chosen for the best answer even.
Here's the code:
<html>
<head>
<title>emarket.com</title>
<link rel="stylesheet" type="text/css" href="./style.css"/>
</head>
<header>
<h1>emarket.com</h1>
<h1>Post Ad</h1>
</header>
<body>
<?php
if(!empty($_POST)){
$title=$_POST['title'];
$description=$_POST['description'];
$district=$_POST['district'];
$phone=$_POST['phone'];
$catagory=$_POST['catagory'];
$price=$_POST['price'];
mysql_connect("localhost","root","");
mysql_select_db("maindb");
mysql_query("INSERT into allads VALUES(NULL,'$title','$phone','$description', '$price','$district','$catagory')");
echo "<span style='background-color: deepskyblue;'>Your advert is now online!</span>";
}
?>
<form class="postad" method="post" action="">
<fieldset><caption><h2>Post New Advert</h2></caption></fieldset>
<fieldset>
<label>Title</label><br/>
<input type="text" name="title" class="form-text" required>
</fieldset>
<fieldset>
<label>Description</label><br/>
<input name="description" class="form-text" required>
</fieldset>
<fieldset>
<label>District</label><br/>
<select name="district"required>
<option selected>Colombo</option>
<option>Kandy</option>
<option>Matara</option>
<option>Galle</option>
</select>
</fieldset>
<fieldset>
<label>Category</label><br/>
<select name="catagory"required>
<option value="Electronics">Electronics</option>
<option value="Property">House and Property</option>
<option value="Auto">Automobiles</option>
<option value="Misc">Miscellaneous</option>
</select>
</fieldset>
<fieldset>
<label>Phone</label><br/>
<input type="tel" name="phone" maxlength="10" class="form-text" required>
</fieldset>
<fieldset>
<label>Price</label><br/>
Rs. <input type="number" name="price" class="form-text" required>
</fieldset>
<fieldset>
<input type="submit" name="submit" value="submit"/>
</fieldset>
</form>
</body>
</html>
This happened after I entered the PHP parts, it was visible in Firefox before that. Other files having PHP, like the home page, works fine. In chrome not only the website is visible, it works fine too. Stuff from the form gets inserted into the sql table without any problems.
Do you have the slightest idea of how vulnerable you are to mysql injection attacks? Please start using pdo. mysql_* is deprecated.
I've cleaned the function for you. The php part will only be executed once you click the submit button.
<?php
mysql_connect("localhost","root","");
mysql_select_db("maindb");
if(isset($_POST['submit']))
{
$title=isset($_POST['title']) ? $_POST['title'] : '';
$description=isset($_POST['description']) ? $_POST['description'] : '';
$district=isset($_POST['district']) ? $_POST['district'] : '';
$phone=isset($_POST['phone']) ? $_POST['phone'] : '';
$catagory=isset($_POST['catagory']) ? $_POST['catagory'] : '';
$price=isset($_POST['price']) ? $_POST['price'] : '';
if(!empty($title) && !empty($description) && !empty($district) && !empty($phone) && !empty($catagory) && !empty($price))
{
$q = mysql_query("INSERT into allads VALUES(NULL,'$title','$phone','$description', '$price','$district','$catagory')");
if($q)
{
echo "<span style='background-color: deepskyblue;'>Your advert is now online!</span>";
}
else
{
echo "Could not update DB";
}
}
}
?>
<html>
<head>
<title>emarket.com</title>
<link rel="stylesheet" type="text/css" href="./style.css"/>
</head>
<header>
<h1>emarket.com</h1>
<h1>Post Ad</h1>
</header>
<body>
<form class="postad" method="post" action="">
<fieldset><caption><h2>Post New Advert</h2></caption></fieldset>
<fieldset>
<label>Title</label><br/>
<input type="text" name="title" class="form-text" required>
</fieldset>
<fieldset>
<label>Description</label><br/>
<input name="description" class="form-text" required>
</fieldset>
<fieldset>
<label>District</label><br/>
<select name="district"required>
<option selected>Colombo</option>
<option>Kandy</option>
<option>Matara</option>
<option>Galle</option>
</select>
</fieldset>
<fieldset>
<label>Category</label><br/>
<select name="catagory"required>
<option value="Electronics">Electronics</option>
<option value="Property">House and Property</option>
<option value="Auto">Automobiles</option>
<option value="Misc">Miscellaneous</option>
</select>
</fieldset>
<fieldset>
<label>Phone</label><br/>
<input type="tel" name="phone" maxlength="10" class="form-text" required>
</fieldset>
<fieldset>
<label>Price</label><br/>
Rs. <input type="number" name="price" class="form-text" required>
</fieldset>
<fieldset>
<input type="submit" name="submit" value="submit"/>
</fieldset>
</form>
</body>
</html>
?>
Edit :- IN situations like these, it's always better to put your php code before <html>
Also, what's your filename in which all this code exists? Put that filename in the <Form action="filenamehere.php">.
If it still doesn't work, upload it somewhere to let me have a closer look.
Your header tag should be inside the body tag.
<body>
<header>
<h1>emarket.com</h1>
<h1>Post Ad</h1>
</header>
Like #Akshay said, you should be using PDO, however you should be escaping your input using something like mysql_real_escape_string($value) before putting it into the database if you aren't using PDO.
OK so I have two different types of forms and I want to use one form to submit them both. I am using a auto-responder form for form1 fields= first, last and email. My second form is a contact me form fields= name. email and a body field. I am trying to use both these forms at one shot. I have a form that will post fields to each form (INDEX.PHP) the problem is I am not sure how to set up form one to post fields into form1 and form2 the way I want. I want to use the fields that match from form index.php to both the other forms (form1, form2). so name and email will go to both forms and the body field will go to form2. The main form will post first and last in the name field of form2....also as you can see from form 1 and 2 each form has a some sort of redirect page I need to work around.?
I have main form:
Index.php
<html>
<head>
<title>Main Form</title>
</head>
<body>
<h2>Winner Aution Item Request Form</h2>
<p><span class="error"><FONT><font color="red">* required field.</font></span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
First Name: <input type="text" name="first_name" value="<?php echo $first_name;?>">
<FONT><font color="red"> *</font>
<br>
Last Name: <input type="text" name="last_name" value="<?php echo $last_name;?>"> <FONT><font color="red"> *</font>
<br>
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<FONT><font color="red"> *</font>
<br><br><i><b>Copy and paste auction item name below.</b></i><br>
Product Name: <input type="text" name="product_Name" rows="1" cols="10">
<?php echo $product_Name;?><FONT><font color="red"> *</font>
<input type="Submit" value="Submit" name="submit"></input>
</form>
</body>
</html>
the above form was found on a website and was pretty close to what I want it to do but not exactly....
Form1
<?php session_start(); ?>
<html>
<head>
<title>autoresponder</title>
</head>
<body>
<center>
<table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;">
<tr><td>
<form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
<strong><font color="#660000">Your First Name:</font></strong>
<input type="text" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#660000">Your Last name:</font></strong>
<input type="text" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#000066">Email address:</font></strong><br>
<input type="text" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
<input type="image" src="http://blog.jeremyahenry.com/mailermanager/images/go-button.gif" name="submit" value="Submit"><br>
<input type="hidden" name="r" value="4">
<input type="hidden" name="a" value="sub">
<input type="hidden" name="ref" value="none">
<br>
<font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes
<input type="RADIO" name="h" value="0" checked="checked">No<br>
</font>
</form>
</td></tr>
</table>
</center>
</body>
</html>
Form 2
<?php session_start(); ?>
<html>
<head>
<title>request form</title>
<style>p{font:10pt arial;}</style>
</head>
<body>
<form action="contact_me/process.php" method=post>
<table align=left border=0 height=300>
<tr>
<td nowrap>
<p> Your name:
<input maxlength=25 name=name size=25>
</td>
</tr>
<tr>
<td nowrap>
<p> Your email:
<input name=from size=25 maxlength=25>
</td>
</tr>
<tr>
<td colspan=2>
<center>
<p align=center>Enter your Auction item Name below:
<br>
<textarea cols=50 name=message rows=7></textarea>
<p align=center>
<input type=submit value="Send Message">
<input type=reset value=Reset name="reset">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
ass you can see from the code I was going to use sessions. But not to familiar with it even though I have experience with php I am still quite new to it and need help. I want to pars form data to both forms. and the product name to form two. any help on this would be greatly appreciated.. I hope this is clear enough for some one out there to help.....
Ok New code Three forms 1.main form submits information to form1 and form2.
I have set up using a session so I have: session.php
<?php
session_start();
// store session data
$_SESSION['af_first_name'] = $af_first_name;
$_SESSION['af_last_name'] = $af_last_name;
$_SESSION['af_email'] = $af_email;
$_SESSION['cf_address'] = $cf_item_name;
?>
That handles variables.
My new code for index.php
<?php
// including the session file
require_once("session_start.php")
?>
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
?>
</head>
<body>
<h2>Winner Aution Item Request Form</h2>
<p><span class="error"><FONT><font color="red">* required field.</font></span></p>
<form name="form1">
First Name: <input type="text" name="$af_first_name" id="af_first_name" value="<?php if(isset($_SESSION['af_first_name'])){echo stripslashes($_SESSION['af_first_name']); unset($_SESSION['af_first_name']); } ?>" /><br>
Last Name: <input type="text" name="$af_last_name" id="af_last_name" value="<?php if(isset($_SESSION['af_last_name'])){echo stripslashes($_SESSION['af_last_name']); unset($_SESSION['af_last_name']); } ?>" /><br>
E-Mail: <input type="text" name="$af_email" id="af_email" value="<?php if(isset($_SESSION['af_email'])){echo stripslashes($_SESSION['af_email']); unset($_SESSION['af_email']); } ?>" /><br>
</form>
<form name="form2">Copy and Paste Auction Name Below!<br>
Product Name <br><input type="text" name="$cf_item_name" id="cf_item_name" value="<?php if(isset($_SESSION['cf_item_name'])){echo stripslashes($_SESSION['cf_item_name']); unset($_SESSION['cf_item_name']); } ?>" /><br>
<input type="Submit" value="Submit" name="submit" onsubmit="form2.submit(); form3.submit();"></input>
That form takes input and sets to session. Session.php picks it up and places it in variable form. From here I used a strip for the underscores. and when it goes to form1 and form2 varables pick it up and fill in the form. Here is my new form1
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
stripZlashes($_SESSION['_mf']);
endif;
// including the session file
require_once("session_start.php")
?>
<center>
<table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;"> <tr><td>
<form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
<strong><font color="#660000">Your First Name:</font></strong>
<input type="text" id="$af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#660000">Your Last name:</font></strong>
<input type="text" id="$af_last_name" value="<?php echo (!empty($_SESSION['_af']['af_last_name'])?$_SESSION['_af']['af_last_name']:'') ?>" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#000066">Email address:</font></strong><br>
<input type="text" id="$af_email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
<input type="image" src="http://newsletter.jeremyahenry.com/images/go-button.gif" name="submit" value="Submit"><br>
<input type="hidden" name="r" value="4">
<input type="hidden" name="a" value="sub">
<input type="hidden" name="ref" value="none">
<br>
<font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes
<input type="RADIO" name="h" value="0" checked="checked">No<br>
</font></form>
</td></tr></table>
</center>
<?php
if(!empty($_SESSION['_mf'])):
unset($_SESSION['_mf']);
endif;
?>
form2:
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
stripZlashes($_SESSION['_mf']);
endif;
// including the session file
require_once("session_start.php")
?>
<form action="process.php" method=post>
<table align=left border=0 height=300>
<tr>
<td nowrap>
<p> Your name:
<input maxlength=25 name="af first name" id="af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" size=25> />
</td</tr>
<tr>
<td nowrap>
<p> Your email:
<input name=af email id="af email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" size=25 maxlength=25> />
</td></tr>
<tr>
<td colspan=2>
<center>
<p align=center>Enter your Auction item Name below:
<br>
<input name="cf item name" id="cf item name" value="<?php echo (!empty($_SESSION['_cf']['cf_item_name'])?$_SESSION['_cf']['cf_item_name']:'') ?>" rows="1" />
<p align=center>
<input type=submit value="Send Message">
</td></tr></table>
</form>
</center>
Ok now i have an issue with it submitting correctly...
<form name="form1">
<input type="text" value="" name="somename" onkeyup="form2.somename.value=this.value" />
</form>
<form name="form2">
<input type="text" value="" name="somename" />
</form>
check out the above code. hope this could be helpful. Or if this is not the result which you require. so you can be brief with your requirements in reply.
I don't know the usage or need of your implementation: maybe it is like a 3 step registration form?
It could be done in different ways without complicating it too much.
You could put all three forms in the same page and only showing the right one
according to th data being posted to the same page. It is the old way of doing things.
With Ajax calls, templates and javascript it could be don simpler but it depends on
your experience.
on each element you can mention as per their relevent events, such as
Ex. onkeyup="form2.elementname.value=this.value"
In my register form, if a validation message needs to appear when the user clicks submit, the whole text out of all the boxes disappears, meaning they have to start again!
What PHP code do I need to add so the data remains?
Username<span class="required">*</span>
<input name="user_name" type="text" id="user_name" minlength="5" >
Full Name<span class="required">*</span>
<input name="full_name" type="text" id="full_name" size="30"
Nationality <span class="required">*</span>
<select name="nationality" id="select8">
<option value="" selected></option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
</select>
<p align="center">
<input name="doRegister" type="submit" id="doRegister" value="Register">
</p>
EDIT:
I have tried this:
<?php
$email_field = ($_POST['usr_email']);
?>
Email<span class="required">*</span>
<input type="text" id="usr_email3" name="usr_email" value="<?php echo
$email_field; ?>" />
but it says usr_email is not defined
As described in the HTTP specs, HTTP is stateless. That means that eventhough the user got to the page through a previous page the server has no idea of this. Each request is completely new, so it cant just send the previous output back.
You'll have to read the values send to your form out of $_POST, and resend that. For example:
<?php
//If the POST parameter has been send, set it to the $username variable. Otherwise make it empty.
$username = array_key_exists('username', $_POST) ? $_POST['username'] : '';
?>
<form name='f1' method='POST'>
<!-- Show username as its value, thus preserving state. -->
Name: <input type='text' value='<?php echo $username ?>' name='username' />
<input type='submit' value='Go' />
</form>
For select inputs (usually dropdown) you need to set the selected attribute on the correct option. As such:
<?php
$gender = array_key_exists('gender', $_POST) ? $_POST['gender'] : 'unknown'; //Default to unknown
?>
<form name='f1' method='POST'>
<select name='gender'>
<!-- The $gender will be the value of each option. -->
<option <? if($gender == 'unknown') { ?> selected <? } ?> value='unknown'>Unknown</option>
<option <? if($gender == 'male') { ?> selected <? } ?> value='male'>Male</option>
<option <? if($gender == 'female') { ?> selected <? } ?> value='female'>Female</option>
</select>
<input type='submit' value='Go' />
</form>
However i still recommend you buy a proper book, or read more tutorials. After you feel more comfortable as a developer you can explore and find these solutions youself, as we all here did once.
<input name="user_name" type="text" id="user_name" minlength="5" value="<?php if(isset($_POST['user_name'])) { echo $_POST['user_name']; } ?>" >