0

I'm having trouble with this for some reason. Basically i'm trying to make it so that one person can go through. If the users name is equal to "Megan" "Renae" then the output will be Hello, "Megan" "Renae" but if there is anything else I want it to output I do not know you. I know this is probably something extremely simple and it is just going over my head but if someone could help you would stop my hair from turning grey! Thank you in advance to anyone that responds.

<form method = "POST" action = " ">
<p>Please enter your first name: <input type="text" name="fName"><br>
<p>Please enter your last name: <input type="text" name="lName"><br><br>
<input type="submit" class="btnSubmit"  name="submit"></p>
</form>

<?php
if ($_POST['submit'] != "") {
if ($_POST['fName'] = "Megan") {
 if ($_POST['lName'] = "Renae") {
 echo "<p>Hello, Megan Renae</p>"; }
else {
echo "<p>I do not know you</p>";     
}}}
?>
Megan
  • 23
  • 1
  • 7

1 Answers1

1

This is the PHP snippet you are looking for:

<?php
    if ($_POST['fName'] == 'Megan' && $_POST['lName'] == 'Renae') {
       echo '<p>Hello, Megan Renae</p>'; 
    }
    else {
        echo '<p>I do not know you</p>';     
    }
?>

In the if statements where you have $_POST[...] = 'some value' you need to use == to compare the values instead of = which sets the value of the variable.

Phiter
  • 14,570
  • 14
  • 50
  • 84
Andrew
  • 1,322
  • 14
  • 20