Jump to content

[SOLVED] Parse error: syntax error, unexpected T_ELSEIF


drax

Recommended Posts

Hi all

 

I'm completely new to php and keep hitting problems that are driving me mad. Could someone be kind enough to look at my code and tell me what stupid mistake I am making?

 

<?php
$step=isset($_POST['step'])?$_POST['step']:1;

if($step==1)  
{
?>
<FORM METHOD="POST"><H2>Step 1</H2><BR>
<INPUT TYPE="HIDDEN" NAME="step" value="2">
<INPUT TYPE="TEXT" Name="username" value="Dave Smith">
<INPUT TYPE="SUBMIT">
</FORM>
<?
elseif($step==2)
{
$username=$_POST['username'];
?>
<FORM METHOD="POST"><H2>Step 2</H2><BR>
<INPUT TYPE="HIDDEN" NAME="step" value="3">
<INPUT TYPE="HIDDEN" NAME="username" value="<?=$username;?>">
<INPUT TYPE="TEXT" Name="email" value="[email protected]">
<INPUT TYPE="SUBMIT">
</FORM>
<?
}
else {
<H2>Step 3</H2><BR>
Username: <?=$_POST['username'];?> <BR>
Email: <?=$_POST['email'];?><BR>
}
?>

 

I get the error "Parse error: syntax error, unexpected T_ELSEIF on line 22"

I'm guessing it's a syntax error but have reached the point where I can't see the wood for the trees!

 

any help would be great

Cheers

 

<?php

$step=isset($_POST['step'])?$_POST['step']:1;

if ($step==1) {
?>
<FORM METHOD="POST"><H2>Step 1</H2><BR>
<INPUT TYPE="HIDDEN" NAME="step" value="2">
<INPUT TYPE="TEXT" Name="username" value="Dave Smith">
<INPUT TYPE="SUBMIT">
</FORM>
<?php
} elseif($step==2) {
  $username = $_POST['username'];
?>
<FORM METHOD="POST"><H2>Step 2</H2><BR>
<INPUT TYPE="HIDDEN" NAME="step" value="3">
<INPUT TYPE="HIDDEN" NAME="username" value="<?=$username;?>">
<INPUT TYPE="TEXT" Name="email" value="[email protected]">
<INPUT TYPE="SUBMIT">
</FORM>
<?php
} else {
<H2>Step 3</H2><BR>
Username: <?=$_POST['username'];?> <BR>
Email: <?=$_POST['email'];?><BR>
}

?>

This is all in php

 

else {

<H2>Step 3</H2><BR>

Username: <?=$_POST['username'];?> <BR>

Email: <?=$_POST['email'];?><BR>

}

?>

 

so change to

 

else {

?>

<H2>Step 3</H2><BR>

Username: <?=$_POST['username'];?> <BR>

Email: <?=$_POST['email'];?><BR>

<?php

}

?>

 

Thanks for the replies, they were scary fast!

 

Thorpe - I tried your and got

 

"Parse error: syntax error, unexpected '<'  on line 32" - prob just highlighting another mistake I made.

 

Revraz - yours seemed to fix it

 

Thank you both so much for your help. Time to crack on and no doubt hit more walls - I'll be back!

 

Cheers

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.