...

View Full Version : Cannot seem to find the error



blackrain87
11-06-2010, 02:26 AM
Hello there,
I have created a page that just has a couple while loops to display some content depending on the url. Here is the page below.


<?php
session_start();
require_once 'database.php';
include("header.php");
echo '<div id="leftnav">';
include("nav.php");
echo '</div><div id="content"><div class="con">';
if (isset($_SESSION['mod'])) {
?>
<a href="?action=userlist">User List</a><br>
<a href="?action=loginattempts">Login Attempts</a><br>
<a href="?action=tickets">Support Tickets</a><br>
<?php
if(isset($_GET['action']) && strcasecmp($_GET['action'], "userlist") == 0) {
?>
<div class="con">
<table>
<tr>
<td>Username</td><td>Location</td><td>Pennies</td><td>Stamleft</td><td>Stamina</td>
<td>Defense</td><td>Strength</td></tr>
$userlist="SELECT username,location,Pennies,stamleft,stamina,defense,strength FROM user";
$userlist2=mysql_query($item,$conn);
while($users=mysql_fetch_array($item2)){
?>
<tr><td><? echo $users['username']; ?></td><td><? echo $users['location']; ?></td><td>
<? echo $users['Pennies']; ?></td><td><? echo $users['stamleft']; ?></td><td>
<? echo $users['stamina']; ?></td><td><? echo $users['defense']; ?></td><td>
<? echo $users['strength']; ?></td></tr>
<?php
} // end of while
?>
</table>
<?php
} // end if of userlist
elseif(isset($_GET['action']) && strcasecmp($_GET['action'], "loginattempts") == 0) {
?>
<div class="con">
<table>
<tr>
<td>IP</td><td>Email Attempt</td><td>Time</td><td>Red</td></tr>
$attempts="SELECT * FROM login_attempts";
$attempts2=mysql_query($item,$conn);
while($logins=mysql_fetch_array($item2)){
?>
<tr><td><? echo $logins['ip']; ?></td><td><? echo $logins['email']; ?></td>
<td><? echo $logins['time']; ?></td><td><? echo $logins['red']; ?></td></tr>
<?php
} // end of while
?>
</table>
<?php
} // end if of loginattempts THIS IS LINE 52!!!!!!
elseif(isset($_GET['action']) && strcasecmp($_GET['action'], "tickets") == 0) {
?>
<div class="con">
<table>
<tr>
<td>Description</td><td>Username</td><td>Time</td><td>Status</td><td>Level</td>
</tr>
<?php
$item="SELECT * FROM tickets";
$item2=mysql_query($item,$conn);
while($items=mysql_fetch_array($item2)){
?>
<tr><td><? echo $items['descrip']; ?></td><td><? echo $items['username']; ?></td><td>
<? echo $items['time']; ?></td><td><? echo $items['status']; ?></td><td>
<? echo $items['level']; ?></td></tr>
<?php
} // end of while
?>
</table>
<?php
}else{
} // end if of tickets


}else{ // if for session set
echo 'You must be a mod to view this page.';
}
?>



But I get this error Parse error: syntax error, unexpected '}' in /home2/newestfu/public_html/*****/******.php on line 52


Line 52 is marked. I cannot figure out why it is there. Usually it's because I forget to close one but I though I had all of them closed, which I have checked.

Any help would be appreciated.

Dormilich
11-06-2010, 02:44 AM
you see those } marked as "end of while"? there is no while() loop til that point, only if()s.

PS. indentation helps keeping track of the nesting and the {}.

blackrain87
11-06-2010, 02:46 AM
Just by looking at what you were talking about, I found the real problem. There is a while for each end, but I forgot to put the <?php tags to start it :o

DrDOS
11-06-2010, 02:59 AM
Stuff like this
<div class="con">
<table>
<tr>
<td>Description</td><td>Username</td><td>Time</td><td>Status</td><td>Level</td>
</tr> can all be echoed to the page. Also, except for the stuff in the loops you can save the variables and echo them at the end of the script. That way you can make it one long script without all the php opening and closing tags.

blackrain87
11-06-2010, 05:10 AM
So I could literally do this?



$text1 = '<div class="con">
<table>
<tr>
<td>Description</td><td>Username</td><td>Time</td><td>Status</td><td>Level</td>
</tr> ';

echo $text1;



And I could use that anywhere?

:eek:

DrDOS
11-06-2010, 05:18 AM
So I could literally do this?



$text1 = '<div class="con">
<table>
<tr>
<td>Description</td><td>Username</td><td>Time</td><td>Status</td><td>Level</td>
</tr> ';

echo $text1;



And I could use that anywhere?

:eek:
Yes you could. You could echo some stuff into the style part, some into the javascript part and some into the body, so you would only need three big block of php plus any separate tags for misc data like forms.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum