Jump to content

[SOLVED] Parse error: syntax error, unexpected T_ELSEIF


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="Dave@Smith.com">
<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="Dave@Smith.com">
<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

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.