Peter! Posted July 18, 2007 Share Posted July 18, 2007 Hiya, I have been learning PHP for about...hmm... 2 hours? I have written this from what I have learnt and as a noob, cannot work out whats wrong. Probably something stupidly simple, but like I said.. 2 hours! <html> <body> <?php function writeName($name) { echo $name . " peter"; } if ($name=="peter"); writeName(); else echo "Wrong Person"; ?> </body> </html> Oh and I get this error: Parse error: parse error, unexpected T_ELSE in test.php on line 12 Quote Link to comment Share on other sites More sharing options...
lewis987 Posted July 18, 2007 Share Posted July 18, 2007 you havent defined $name, how about something (trying to make it simple) a form? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 18, 2007 Share Posted July 18, 2007 Hiya, I have been learning PHP for about...hmm... 2 hours? I have written this from what I have learnt and as a noob, cannot work out whats wrong. Probably something stupidly simple, but like I said.. 2 hours! <html> <body> <?php function writeName($name) { echo $name . " peter"; } if ($name=="peter"); writeName(); else echo "Wrong Person"; ?> </body> </html> Oh and I get this error: Parse error: parse error, unexpected T_ELSE in test.php on line 12 and on the if and elses you are missing the { and } the code should look like: <?php function writeName($name) { echo $name . " peter"; } if ($name=="peter") { writeName(); } else { echo "Wrong Person"; } ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 18, 2007 Share Posted July 18, 2007 This code doesn't make much sense... if ($name=="peter"); On this line, there should be no semi-colon at the end. Also, where are you getting the variable $name? Do you have a form that you submit? writeMyName(); You are calling your function, but you are not putting in the required parameter, name. Could you explain a little more on EXACTLY what you are trying to get this code to do? Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted July 18, 2007 Share Posted July 18, 2007 Oooh ooh . . . I have seen this before. <html> <body> <?php function writeName($name) { echo $name . " peter"; } if ($name=="peter"); writeName(); else echo "Wrong Person"; ?> </body> </html> It is in the echo $name . " peter"; that he is trying to give the $name variable a value. I saw this in one of the tutorials, but I can't quite remember which one. Quote Link to comment Share on other sites More sharing options...
lewis987 Posted July 18, 2007 Share Posted July 18, 2007 shouldnt it read: <html> <body> <?php if($_POST['continue']){ if($_POST['name'] == ""){ echo "You have not entered a name"; } $name = $_POST['name']; function writeName($name) { echo $name . " peter"; } if ($name=="peter"){ writeName($name); }else{ echo "Wrong Person"; } }else{ ?> <form action="" method="post"><input name="name" type="text" /><br /> <input name="continue" type="submit" value="Continue" /></form> <?PHP } ?> </body> </html> Go ahead and correct me it is wrong Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.