Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Cannot seem to find the error

    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 Code:
    <?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.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    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 {}.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    blackrain87 (11-06-2010)

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Stuff like this
    PHP Code:
    <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.

  • #5
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts
    So I could literally do this?

    PHP Code:
    $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?


  • #6
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by blackrain87 View Post
    So I could literally do this?

    PHP Code:
    $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?

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •