NealeWeb Posted May 10, 2011 Share Posted May 10, 2011 I am following a tutorial and have come across an error, i have checked that i made no mistakes when copying and have tried everything i know to try but im not that experienced so ive had no luck. Could someone pls point out the mistake for me. Parse error: syntax error, unexpected $end in /members.php on line 30 members.php <?php session_start(); require 'database.php'; $nuser=$_SESSION['user']; $auser=$_SESSION['admin']; if($nuser){ $userfinal=$nuser; }elseif($auser){ $userfinal=$auser; } if(isset($userfinal)){ $Members = mysql_query("SELECT user FROM characters WHERE level ='1' ORDER BY exp DESC") or die(mysql_error()); $numRowsMembers = mysql_num_rows($Members); ?> <table border="0"> <?php for($count = 1; $count <= $numRowsMembers; $count++) { $name = mysql_fetch_array($Members); ?> <tr> <?php echo '<td><a href="member_profile.php?username=' . $name['user'] . '">' . $name['user'] . '</a></td>'; ?> </tr> <?php <<<<<<<<<< Line 30 } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/235996-parse-error-syntax-error-unexpected-end/ Share on other sites More sharing options...
Tonic-_- Posted May 10, 2011 Share Posted May 10, 2011 I suggest fixing this: echo '<td><a href="member_profile.php?username=' . $name['user'] . '">' . $name['user'] . '</a></td>'; Maybe changing it to echo "<td><a href=\"member_profile.php?user=" . $name['user'] . "\">" . $name['user'] . "</a></td>"; Another suggestion is to use a while loop instead of for. <?php session_start(); require 'database.php'; $nuser=$_SESSION['user']; $auser=$_SESSION['admin']; if($nuser){ $userfinal=$nuser; }elseif($auser){ $userfinal=$auser; } if(isset($userfinal)){ $Members = mysql_query("SELECT user FROM characters WHERE level ='1' ORDER BY exp DESC") or die(mysql_error()); ?> <table border="0"> <?php while($name = mysql_fetch_assoc($Members)) { ?> <tr> <?php echo "<td><a href=\"member_profile.php?user=" . $name['user'] . "\">" . $name['user'] . "</a></td>"; ?> </tr> <?php } ?> </table> Either way it should work. Quote Link to comment https://forums.phpfreaks.com/topic/235996-parse-error-syntax-error-unexpected-end/#findComment-1213264 Share on other sites More sharing options...
NealeWeb Posted May 10, 2011 Author Share Posted May 10, 2011 Thankyou for the help but i am now getting this error Parse error: syntax error, unexpected $end in /members.php on line 31 members.php <?php session_start(); require 'database.php'; $nuser=$_SESSION['user']; $auser=$_SESSION['admin']; if($nuser){ $userfinal=$nuser; }elseif($auser){ $userfinal=$auser; } if(isset($userfinal)){ $Members = mysql_query("SELECT user FROM characters WHERE level ='1' ORDER BY exp DESC") or die(mysql_error()); ?> <table border="0"> <?php while($name = mysql_fetch_assoc($Members)) { ?> <tr> <?php echo "<td><a href=\"member_profile.php?user=" . $name['user'] . "\">" . $name['user'] . "</a></td>"; ?> </tr> <?php } ?> </table> <<<<<<<<<< Line 31 Quote Link to comment https://forums.phpfreaks.com/topic/235996-parse-error-syntax-error-unexpected-end/#findComment-1213269 Share on other sites More sharing options...
Tonic-_- Posted May 10, 2011 Share Posted May 10, 2011 Thankyou for the help but i am now getting this error Parse error: syntax error, unexpected $end in /members.php on line 31 members.php <?php session_start(); require 'database.php'; $nuser=$_SESSION['user']; $auser=$_SESSION['admin']; if($nuser){ $userfinal=$nuser; }elseif($auser){ $userfinal=$auser; } if(isset($userfinal)){ $Members = mysql_query("SELECT user FROM characters WHERE level ='1' ORDER BY exp DESC") or die(mysql_error()); ?> <table border="0"> <?php while($name = mysql_fetch_assoc($Members)) { ?> <tr> <?php echo "<td><a href=\"member_profile.php?user=" . $name['user'] . "\">" . $name['user'] . "</a></td>"; ?> </tr> <?php } ?> </table> <<<<<<<<<< Line 31 I see the problem now, I didn't see notice the if statement above the $members query. Above </table> change it to <?php } } ?> You are not closing if(isset($userfinal)){ Quote Link to comment https://forums.phpfreaks.com/topic/235996-parse-error-syntax-error-unexpected-end/#findComment-1213270 Share on other sites More sharing options...
NealeWeb Posted May 10, 2011 Author Share Posted May 10, 2011 Ok great no error anymore thankyou but im now getting a blank page with no results. Any idea what i did wrong? Quote Link to comment https://forums.phpfreaks.com/topic/235996-parse-error-syntax-error-unexpected-end/#findComment-1213273 Share on other sites More sharing options...
Tonic-_- Posted May 10, 2011 Share Posted May 10, 2011 Could be a problem I did somewhere if you used the while statement instead of for, to confirm this use your original code with the <?php }}?> fix and the echo, if it still does it then it can be the SQL Query statement or somewhere else in the code. I'm not all to familiar with using mysql_query or mysql_fetch_assoc as I use a different connector. Or maybe changing this coding if($nuser){ $userfinal=$nuser; }elseif($auser){ $userfinal=$auser; } to if(!empty($nuser)){ $userfinal=$nuser; }elseif(!empty($auser)){ $userfinal=$auser; } else { echo "No sessions found"; } Quote Link to comment https://forums.phpfreaks.com/topic/235996-parse-error-syntax-error-unexpected-end/#findComment-1213275 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.