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
https://forums.phpfreaks.com/topic/60650-php-code/
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
https://forums.phpfreaks.com/topic/60650-php-code/#findComment-301727
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
https://forums.phpfreaks.com/topic/60650-php-code/#findComment-301728
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
https://forums.phpfreaks.com/topic/60650-php-code/#findComment-301744
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
https://forums.phpfreaks.com/topic/60650-php-code/#findComment-301760
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.