I am very new to PHP and currently working on developing my first form. With the below code sample I am trying to achieve two things.
- If the fields for "name" or "email" are filled out in the form, then it will post "Your name is: "name" and "Your email is:"email".
- If a field is not filled out, then it will display nothing at all.
I believe this needs to be done with an IF statement but I am having a hard time finding anything showing the protocol for if the field is empty. Any help would be greatly appreciated.
<form action="Test.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
<?php
$name = $_POST["name"];
if($name="name") {
echo "Your name is: $_POST["name"]" ;
} else {
echo "";
}
?>
<br>
<?php
$email = $_POST["email"];
if($email = "email") {
echo "Your email is: $_POST["email"]" ;
} else {
echo "";
}
?>
"quotes within a"-quoted string, nor are you allowed to use quoted array keys within"-quoted strings. Your if() tests are doing ASSIGNMENTS (=), not testing for equality (==). Basically, you need to study basic PHP syntax a bit more.echo "Your name is: " . $name;etc. If you want to check if a name was entered,if(!empty($_POST['name']))orif(isset...- Wait for the answers to roll in...vvvvv