Current Events > Anybody notice what's wrong with my php code?

Topic List
Page List: 1
NuclearPandaz
12/17/17 2:29:43 PM
#1:


<?php
function myFunction(){
$firstName = $_GET["fname"];
$midName=$_GET["mname"];
$lastName = $_GET["lname"];

if (($firstName !== null) && ($midName == "") && ($lastName == ""))
echo "<p>Hello $firstName! Welcome to php</p>";

else if
(($firstName !== null) && ($lastName !== null) && ($midName == null))
echo "<p> Hello $firstName $lastName ! It is a pleasure to meet you</p>";

else if
(($firstName !== null) && ($midName !== null) && ($lastName !== null)
echo "<p>Hello $firstName $midName $lastName ! Your middle name is very unique.</p>";
else if
(($firstName == null) && ($midName == null) && ($lastName == null)
echo "<p>"You did not supply any names</p>";

}

myFunction();
?>

That's the code, and I'm using XAMPP. It doesn't work and I don't knwo where I;m going wrong.
If you want the html just ask.
---
nothingness
... Copied to Clipboard!
gandalfl0
12/17/17 2:35:30 PM
#2:


I cant really remember php, but I think your last two conditions are missing close parens
---
You see a wooden casket where I see a glowing portal.
http://www.last.fm/user/rucus5
... Copied to Clipboard!
Milkman5
12/17/17 2:37:54 PM
#3:


gandalfl0 posted...
I cant really remember php, but I think your last two conditions are missing close parens


yeah this
... Copied to Clipboard!
Flintlock_Staff
12/17/17 2:38:05 PM
#4:


gandalfl0 posted...
I cant really remember php, but I think your last two conditions are missing close parens

---
Currently Playing: Breath of the Wild
... Copied to Clipboard!
NuclearPandaz
12/17/17 2:40:26 PM
#5:


I put that in but it's saying there's an error on this line:

echo "<p>"You did not supply any names</p>";

The error is this

Parse error: syntax error, unexpected 'You' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\Week9Lab\week9labTask1.php on line 25
---
nothingness
... Copied to Clipboard!
Flintlock_Staff
12/17/17 2:42:46 PM
#6:


You have an extra "
---
Currently Playing: Breath of the Wild
... Copied to Clipboard!
NuclearPandaz
12/17/17 2:45:56 PM
#7:


Ok, I changed that and it outputs now but the output is wrong for when they don't enter a name, if they dont it came up as if they entered $firstName
---
nothingness
... Copied to Clipboard!
MacadamianNut3
12/17/17 3:01:48 PM
#8:


Why are you mixing up null and ""

An empty string is not the same thing as null
---
XBL/Steam/R*/Uplay: Barinade88 | Origin: Barinade | BattleNet: Barinade#11210
Roll Tide & Go Irish
... Copied to Clipboard!
Flintlock_Staff
12/17/17 3:03:46 PM
#9:


I'm not too versed in php tbh but maybe try adding some lines for if they didn't enter a name at all to either repromt them or just output whatever you want
---
Currently Playing: Breath of the Wild
... Copied to Clipboard!
MacadamianNut3
12/17/17 3:11:13 PM
#10:


God dammit I didn't mean to delete my post

Anyway, as I was saying, an empty string isn't null and you shouldn't be mixing them up in your conditionals anyway. If they didn't enter a name at all, the program runs on the first if statement because

-an empty string isn't null, so the first condition is true
-the other two fields are empty strings so the other two conditions are true
---
XBL/Steam/R*/Uplay: Barinade88 | Origin: Barinade | BattleNet: Barinade#11210
Roll Tide & Go Irish
... Copied to Clipboard!
NuclearPandaz
12/17/17 9:10:40 PM
#11:


MacadamianNut3 posted...
God dammit I didn't mean to delete my post

Anyway, as I was saying, an empty string isn't null and you shouldn't be mixing them up in your conditionals anyway. If they didn't enter a name at all, the program runs on the first if statement because

-an empty string isn't null, so the first condition is true
-the other two fields are empty strings so the other two conditions are true

Ah, so I would have to do something like $firstName == "" ?
---
nothingness
... Copied to Clipboard!
1337toothbrush
12/17/17 9:21:38 PM
#12:


Yeah, it's in PHP.
---
... Copied to Clipboard!
Topic List
Page List: 1