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:
For
selectinputs (usually dropdown) you need to set the selected attribute on the correct option. As such: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.