Jump to content

Error with code


onthespot

Recommended Posts


<?php
if(isset($_SESSION['leaguesuccess']))
{
   if($_SESSION['leaguesuccess'])
   {
      echo "<h1>League creation successful, now add players and teams</h1>";
  
  echo "<form action='process.php' method='POST'>
  
	<table cellspacing=\"10\">";
	$u = $database->generateUserArray();
	$t = $database->generateTeamArray();

	for ($i = 0; $i < $_SESSION['players']; $i++) 
	{
		echo "
		<tr>
			<td>
				User : <select name='user[$i]'>";
				foreach ($u as $username) {
				echo"<option value='$username'>$username</option>";
				}
				echo"
				</select>
			</td> 
			<td>
				Team : <select name='team[$i]'>
				";
				foreach ($t as $teams) {
				echo"<option value='$teams'>$teams</option>";
				}
				echo"
				</select>
			</td>	
		</tr>";
	}

	echo"

	</table>
	<input type='hidden' name='leagueusers' value="1">
	<input type='submit' value='Submit'></form>";
      
  
   }
   else
   {
      echo "<h1>League creation failed</h1>";
      echo "<p>Sorry, try again.</p>";
   }
   unset($_SESSION['leaguesuccess']);

}

?>

 

Receiving the following error:

 

Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';'

 

I cant see whats wrong? Please help

Link to comment
https://forums.phpfreaks.com/topic/200360-error-with-code/
Share on other sites

Oh my goodness that was horrible to read. You need to work on better code format. Maybe you can read that, but it's a mess for people like us.

 

The error occurs here:

echo"
</table>
<input type='hidden' name='leagueusers' value="1">
<input type='submit' value='Submit'></form>";

 

See that "1"? You forgot to escape them and so you closed out your echo.

Link to comment
https://forums.phpfreaks.com/topic/200360-error-with-code/#findComment-1051472
Share on other sites

You can echo whatever you want, but leave the code out of it. By that, I mean you shouldn't indent the foreach statement to where you finished your echo because it skews the layout. You should have them indented like this:

 

<?php
if(isset($_SESSION['leaguesuccess']))
{
if($_SESSION['leaguesuccess'])
{
	echo "<h1>League creation successful, now add players and teams</h1>";
	echo "<form action='process.php' method='POST'>
  	<table cellspacing=\"10\">";

	$u = $database->generateUserArray();
	$t = $database->generateTeamArray();

	for ($i = 0; $i < $_SESSION['players']; $i++) 
	{
		echo "
		<tr>
			<td>
				User : <select name='user[$i]'>";

		foreach ($u as $username) {
			echo"<option value='$username'>$username</option>";
		}

		echo"
				</select>
			</td> 
			<td>
				Team : <select name='team[$i]'>
				";

		foreach ($t as $teams) {
			echo"<option value='$teams'>$teams</option>";
		}

		echo"
				</select>
			</td>	
		</tr>";
	}

	echo"
	</table>
	<input type='hidden' name='leagueusers' value="1">
	<input type='submit' value='Submit'></form>";
      
  
   }
   else
   {
      echo "<h1>League creation failed</h1>";
      echo "<p>Sorry, try again.</p>";
   }
   unset($_SESSION['leaguesuccess']);
}
?>

 

From that, I can easily go straight down without scrolling etc. It's much clearer.

Link to comment
https://forums.phpfreaks.com/topic/200360-error-with-code/#findComment-1051478
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.