Jump to content

PHP Code


Peter!

Recommended Posts

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

 

Link to comment
Share on other sites

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";
}
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.