problems with forms

I have very little experience with PHP, maybe someone could provide me with some help.

Currently I am trying to code a form.

The problem:

when I fill in the name field and press Send-button I expect the program to leave the name there. But right now it does not. Can someone tell me why?

form <?php if(isset($_GET['name']) && isset($_GET['email']) && isset($_GET['age'])) { if(!empty($_GET['name']) && !empty($_GET['email']) && !empty($_GET['gender']) && !empty($_GET['age'])) { echo "Hello, {$_GET['name']}. All fields are filled!"; } else { echo "One or more fields have not been filled!"; } } else { echo "Hello! Please fill in the fields."; } ?>
<form action="form.php" method="GET">
<input type="text" name="name" <?php if(!empty($_GET["name"])) 
	echo "value=\"{$_GET['name']}\" "; ?> size="40" placeholder="insert name" /> <br/>
<input type="email" name="email" placeholder="e-mail address" size="40"/> <br/>
<input type="number" name="age" placeholder="insert age" size="40"/> <br/>
<label> Gender <br/>
<label> <input type="radio" name="gender" value="male" />  male </label>
<label> <input type="radio" name="gender" value="female" /> female </label>
</label> <br/>
<input type="submit" name="button" value="Send" /> <br/>
</form>

I’ve moved this topic to a more appropriate location for starters.

One thing, move your php to the top of the page. If you are going to use validation and not sparate the code, it needs to primary be where it belongs.

[php]

<?php if(isset($_GET['name']) && isset($_GET['email']) && isset($_GET['age'])) { if(!empty($_GET['name']) && !empty($_GET['email']) && !empty($_GET['gender']) && !empty($_GET['age'])) { $msg = "Hello, {$_GET['name']}. All fields are filled!"; } else { $msg = "One or more fields have not been filled!"; } } else { $msg = "Hello! Please fill in the fields."; } ?> form <?php if ( isset( $msg ) ) echo $msg; ?> " size="40" placeholder="insert name" />


Gender
male female

[/php]

Try this… Your style will come as you develop more.

Code overkill. Your first set of if isset’s are redundant.

If the fields are not empty then they are isset. Also, why are you using GET instead of POST?

Thank you very much! It was helpful!

Sponsor our Newsletter | Privacy Policy | Terms of Service