Jump to content

syntax error, unexpected T_ELSEIF


NLT

Recommended Posts

if(mysql_num_rows($query) == 1)
{
	 $compny = mysql_query("SELECT * FROM company WHERE value='". $comp ."'");
	 $company = mysql_result($compny, 0);
	if(mysql_num_rows($company) == 0)
	{
		echo "Company not found";
		die();
	}
	 $getcompstt = mysql_query("SELECT stat FROM company WHERE value='". $comp ."' LIMIT 1");
	 $getcompstat = mysql_result($getcompstt, 0); 
	elseif($getcompstat == "3")

Link to comment
https://forums.phpfreaks.com/topic/261440-syntax-error-unexpected-t_elseif/
Share on other sites

You should write something describing your problem rather than just post code.

 


if(mysql_num_rows($query) == 1)
{
$compny = mysql_query("SELECT * FROM company WHERE value='". $comp ."'");
$company = mysql_result($compny, 0);
if(mysql_num_rows($company) == 0)
{
	echo "Company not found";
	die();
}
$getcompstt = mysql_query("SELECT stat FROM company WHERE value='". $comp ."' LIMIT 1");
$getcompstat = mysql_result($getcompstt, 0); 
elseif($getcompstat == "3")

 

You have an elseif there at the end that is not attached to any preceding if statement. 

 

if(mysql_num_rows($query) == 1)
{
	 $compny = mysql_query("SELECT * FROM company WHERE value='". $comp ."'");
	 $company = mysql_result($compny, 0);
	if(mysql_num_rows($company) == 0)
	{
		echo "Company not found";
		die();
	}
	 $getcompstt = mysql_query("SELECT stat FROM company WHERE value='". $comp ."' LIMIT 1");
	 $getcompstat = mysql_result($getcompstt, 0); 
	elseif($getcompstat == "3")
	{
		echo "Cannot find company"; 
		die();
	}

 

Sorry for not explaining - I wasn't sure how to.

 

That is the elseif statement, from the elseif I am having trouble, as you know it is giving me errors.

You are running other statements after the preceding if but before you use elseif.  elseif must come immediately after the close of the preceding if:

 

if(condition1)
{
      echo "foo";
}//end of if
elseif(condition2)
{
     echo "bar";
}

 

You have something like:

if(condition1)
{
      echo "foo";
}//end of if

echo "I have some stuff here after if but before elseif--I can't use elseif after this!

elseif(condition2)
{
     echo "bar";
}

You are running other statements after the preceding if but before you use elseif.  elseif must come immediately after the close of the preceding if:

 

if(condition1)
{
      echo "foo";
}//end of if
elseif(condition2)
{
     echo "bar";
}

 

You have something like:

if(condition1)
{
      echo "foo";
}//end of if

echo "I have some stuff here after if but before elseif--I can't use elseif after this!

elseif(condition2)
{
     echo "bar";
}

 

Thank you, I always thought you could add things in between, but nevermind x).

 

EDIT: Fixed, thank you.

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.