So I have been actively learning PHP for the past days and, for practise, I wrote PHP script, which takes HTML Form values.
I tried writing script, where I have 5 persons, and you have to input your name and last name. If it matches with one of the five persons, it sends one message, if not, other. Here it is (Without form part, only PHP):
$first = $_POST["first"];
$last = $_POST["last"];
if ($first == "Jeb") {
if ($last == "Jeb") {
print "Hello!";
} else {
print "I dont know you!";
}
} elseif ($first == "Bob") {
if ($last == "Bob") {
print "Hello!";
} else {
print "I dont know you!";
}
} elseif ($first == "Bill") {
if ($last == "Bill") {
print "Hello!";
} else {
print "I dont know you!";
}
} elseif ($first == "Annie") {
if ($last == "Annie") {
print "Hello!";
} else {
print "I dont know you!";
}
} elseif ($first == "Hugo") {
if ($last == "Hugo") {
print "Hello!";
} else {
print "I dont know you!";
}
} else {
print "I dont know you!";
}
It works great, but I have question- can this be done easier / written shorter? And can this be done using switch statement?
Any respone will be apprecieted!