onthespot Posted May 1, 2010 Share Posted May 1, 2010 <?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 More sharing options...
Ken2k7 Posted May 1, 2010 Share Posted May 1, 2010 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 More sharing options...
onthespot Posted May 1, 2010 Author Share Posted May 1, 2010 Sorry, I wasnt aware it was that bad. My layout has actually improved, used to be all over the place. What would you recommend to improve it? Link to comment https://forums.phpfreaks.com/topic/200360-error-with-code/#findComment-1051474 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2010 Share Posted May 1, 2010 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 More sharing options...
onthespot Posted May 1, 2010 Author Share Posted May 1, 2010 I've never thought of it like that, definately lesson learn't. Cheers Link to comment https://forums.phpfreaks.com/topic/200360-error-with-code/#findComment-1051483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.