Jump to content

Error In Syntax


Russia

Recommended Posts

I got this error:

 

Parse error: syntax error, unexpected '>' in /home/bucket/public_html/inc/func.ban.php on line 56

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
// func.ban.php
// checks the ip to see if it is banned
function checkban($ip)
    {
        // querys database
        $q = mysql_query("SELECT * FROM `banned` WHERE `ip` = '$ip' LIMIT 1");
        $get = mysql_num_rows($q);
        // if found
        if ($get == "1")
            { 
                // deny user access
                $r=mysql_fetch_array($q);
                die("You have been banned from this website for $r[reason].");
            }
    }
// places a ban in the database
function addban($ip,$reason,$legnth)
    {
        // get current time
        $time = time();
        // inserts code into database
        $insert = mysql_query("INSERT INTO `banned` (`ip`,`time`,`long`,`reason`) VALUES ('$ip', '$time', '$legnth', '$reason')") or die("Could not add ban.<br />".mysql.error()."");
        echo "The ip address, $ip, has been added to the ban list.";
    }
// deletes a ban from the database
function delban($id)
    {
        // runs a delete query
        $delete = mysql_query("DELETE FROM `banned` WHERE `id` = '$id' LIMIT 1") or die("Could not remove ban.<br />".mysql.error()."");
        echo "The ip address has been removed from the ban list.";
    }
// lists the bans in the ban admin
function listbans()
    { 
        // link to add ban
        echo "<a href='accounts-banned.php?x=add'>Add Ban</a><p>";
        echo "<table class=\"gridtable\">
        <thead>
    <tr>
        <th scope=\"col\" align=\"center\">IP Address</th>
        <th scope=\"col\" align=\"center\">Reason</th>
        <th scope=\"col\" align=\"center\">Legnth</th>
    </tr>
</thead><tbody>";
        // loop to show all band
        $query = mysql_query("SELECT * FROM `banned` ORDER BY time DESC");
        $num = mysql_num_rows($query);
        if ($num)
            {
        while ($r=mysql_fetch_array($query))
            {
                echo "<tr align=\"center\">;
                echo "<td>$r[ip]</td>";
                echo "<td>$r[reason]</td>";
                echo "<td><a href='accounts-banned.php?x=delete&id=$r[id]'>Delete</a></td>";
                echo "</tr>;
            }
            }
        echo "</tbody></table>";
    }
?>

 

Line 56 is:

echo "<td>$r[ip]</td>";

 

Whats the problem?

Link to comment
Share on other sites

You have many mistakes. On the line before the one you mentioned (line 55 I suppose), you're missing a closing double-quote ("). Also, to use arrays inside of double quotes you must use curly braces. Ex: echo "{$r['ip']}"; Finally, you should always use single (or double, doesn't really matter) quotes when accessing elements of an arrays. So $r['ip'] not $r[ip].

Link to comment
Share on other sites

Thanks. Now I have fixed that problem, I have a new one:

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
// func.ban.php
// checks the ip to see if it is banned
function checkban($ip)
    {
        // querys database
        $q = mysql_query("SELECT * FROM `banned` WHERE `ip` = '$ip' LIMIT 1");
        $get = mysql_num_rows($q);
        // if found
        if ($get == "1")
            { 
                // deny user access
                $r=mysql_fetch_array($q);
                die("You have been banned from this website for $r[reason].");
            }
    }
// places a ban in the database
function addban($ip,$reason,$legnth)
    {
        // get current time
        $time = time();
        // inserts code into database
        $insert = mysql_query("INSERT INTO `banned` (`ip`,`time`,`long`,`reason`) VALUES ('$ip', '$time', '$legnth', '$reason')") or die("Could not add ban.<br />".mysql.error()."");
        echo "The ip address, $ip, has been added to the ban list.";
    }
// deletes a ban from the database
function delban($id)
    {
        // runs a delete query
        $delete = mysql_query("DELETE FROM `banned` WHERE `id` = '$id' LIMIT 1") or die("Could not remove ban.<br />".mysql.error()."");
        echo "The ip address has been removed from the ban list.";
    }
// lists the bans in the ban admin
function listbans()
    { 
        // link to add ban
        echo "<a href='accounts-banned.php?x=add'>Add Ban</a><p>";
        echo "<table class=\"gridtable\">
        <thead>
    <tr>
        <th scope=\"col\" align=\"center\">IP Address</th>
        <th scope=\"col\" align=\"center\">Reason</th>
        <th scope=\"col\" align=\"center\">Legnth</th>
    </tr>
</thead><tbody>";
        // loop to show all band
        $query = mysql_query("SELECT * FROM `banned` ORDER BY time DESC");
        $num = mysql_num_rows($query);
        if ($num)
            {
        while ($r=mysql_fetch_array($query))
            {
                echo "<tr align=\"center\">";
                echo "<td>$r[ip]</td>";
                echo "<td>$r[reason]</td>";
                echo "<td><a href='accounts-banned.php?x=delete&id=$r[id]'>Delete</a></td>";
                echo "</tr>;
            }
            }
        echo "</tbody></table>";
    }
?>

 

Error:

Parse error: syntax error, unexpected '/' in /home/bucket/public_html/inc/func.ban.php on line 62

 

That line is:

 

echo "</tbody></table>";

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.