0

I have a problem, I am getting the Undefined Variable and I'm not sure what's wrong. I have only been working with PHP for the last 3 months, so that might be the main problem hehe.

This is the class:

<?php

class BannedIPs
{
public $id;
public $ip;
public $date;
public $time;
public $reason;

public $Conn;
public $Error;

public function __construct(&$Conn)
{
    $this->id = "";
    $this->ip = "";
$this->date = "";
    $this->time = "";
    $this->reason = "";

    $this->Conn = $Conn;
    $this->Error = false;
}

public function GetByID($strCode)
{
    $strSQL =  "SELECT ";
$strSQL .= "bingoliv_bannedips.* ";
$strSQL .= "FROM bingoliv_bannedips ";
$strSQL .= "WHERE (id = '" . mysqli_real_escape_string($this->Conn, $strCode) . "') ";
$this->GetRecord($strSQL);
}

private function GetRecord($strSQL)
{
    $objRS = mysqli_query($this->Conn, $strSQL);
if (mysqli_num_rows($objRS) == 1)
{
        $arrRS = mysqli_fetch_assoc($objRS);
        $this->id = $arrRs["ID"]; //error here
        $this->ip = $arrRS["IP"];
        $this->date = $arrRS["Date"];
        $this->time = $arrRS["Time"];
        $this->reason = $arrRs["Reason"]; //and here

        $this->Error = false;
    }
else
{
        $this->Error = true;
}
    mysqli_free_result($objRS);
}

public function Insert() //inserts a new banned ip to the database
{
    $strSQL  = "INSERT INTO bingoliv_bannedips (ID, IP, Date, Time, Reason) ";
$strSQL .= "VALUES ( ";
    $strSQL .= "'" . mysqli_real_escape_string($this->Conn, $this->id) . "', ";
$strSQL .= "'" . mysqli_real_escape_string($this->Conn, $this->ip) . "', ";
$strSQL .= "'" . mysqli_real_escape_string($this->Conn, $this->date) . "', ";
    $strSQL .= "'" . mysqli_real_escape_string($this->Conn, $this->time) . "', ";
    $strSQL .= "'" . mysqli_real_escape_string($this->Conn, $this->reason) . "' ";
$strSQL .= ") ";
$resResult = mysqli_query($this->Conn, $strSQL);
}

public function Delete() //deletes using id as an identifier
{
    $strSQL = "DELETE FROM bingoliv_bannedips WHERE id ='" . mysqli_real_escape_string($this->Conn, $this->id) . "' ";
$resResult = mysqli_query($this->Conn, $strSQL);

    $this->id = "";
    $this->ip = "";
$this->date = "";
    $this->time = "";
    $this->reason = "";

$this->Error = false;
}

}

?>

This is the Admin Page:

<?php
require_once "includes/ssi.page.top.php";
require_once "includes/ssi.admincols.start.php";

kickIfInsufficientRights($resConn, $objCurrentPage->RightName, $objCurrentUser->ProfileID, 'admin.php');

handleResultMessage($strResultType, $strResult); #What is this for??

 ?>

<h3><a href="admin.php">Administration</a> &raquo; Banned IPs</h3>
<div class="admin">
<table>

<?php
$strSQL  = "SELECT id FROM bingoliv_bannedips ORDER BY ip ASC ";
$objRS = new ZpPagingRecordset($resConn, $objCurrentUser->PageSize);
$objRS->GetData($strSQL, $intCurPage);
?>
<tr>
<th class="right" colspan="5"><?php echo $objRS->Controls('admin.bannedips.php', '')?></th>
</tr>
<tr class="strong">
<th>ID</th>
<th>IP</th>
<th>Date</th>
<th>Time</th>   
<th>Reason</th>
<th></th>
</tr>
<?php

if (!$objRS->Error)
        {
        $objBannedIPs = new BannedIPs($resConn);
        foreach ($objRS->Data as $arrRS)
        {
                $objBannedIPs->GetByID($arrRS["id"]);
                ?>

                <!-- bam -->
                <tr class="hoverable">

                    <td><?php echo $objBannedIPs->id?></td>
                    <td><?php echo $objBannedIPs->ip?></td>
                    <td><?php echo $objBannedIPs->date?></td>
                    <td><?php echo $objBannedIPs->time?></td>
                    <td><?php echo $objBannedIPs->reason?></td>

                    <td class="right">
                        <?php if ($objCurrentUser->AllowedTo('ADMIN_COUNTRIES_UPDATE'))                   { ?>
                            <a onclick="return zpSure('Deleting a banned ip is permanent!\n\nAre you sure you want to delete this banned ip?')" href="actions/admin.bannedips.delete.php?intCurPage=<?php echo $intCurPage?>&amp;cnt_id=<?php echo $objBannedIPs->id?>" title="delete">
                            <img src="zplib/icons/delete.png" alt="Delete" /></a>
                        <?php } ?>
                    </td>

                </tr>

                <?php
        }
        unset($objBannedIPs);
        ?>
        <?php
        }  
#when no data if found
else
{
        ?>
        <tr>
        <td class="celGridCenterBold" colspan="5"><br />No data found<br />&nbsp;</td>
        </tr>
        <?php
}              
unset($objRS);
?>

</table>
</div><!--/admin-->


<?php

    require_once "includes/ssi.admincols.mid.php";
    require_once "includes/ssi.panel.sidemenu.php";
    require_once "includes/ssi.admincols.end.php";
    require_once "includes/ssi.page.bottom.php";
?>

This is the table:

enter image description here

And finally, this is the error:

enter image description here

3
  • This should probably be closed as too localized. Commented Sep 9, 2011 at 14:15
  • @Alin most not localized questions are already answered Commented Sep 9, 2011 at 14:17
  • @Alin Purcaru - I voted to close too, I agree it is localised, tought it was something more than just a case sensitive problem Commented Sep 9, 2011 at 14:17

3 Answers 3

2

$arrRS is not the same as $arrRs.

From http://www.php.net/manual/en/language.variables.basics.php:

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

Sign up to request clarification or add additional context in comments.

1 Comment

it took me a second to determine it. You were faster, though. +1
1

S should be in capital

$this->id = $arrRs["ID"]; vs $this->id = $arrRS["ID"];

    $this->id = $arrRS["ID"]; 
    $this->ip = $arrRS["IP"];
    $this->date = $arrRS["Date"];
    $this->time = $arrRS["Time"];
    $this->reason = $arrRS["Reason"];

5 Comments

can't believe I did not see this, too tired I guess
You know what? Go sleep, take a break. In case like this, it's the best thing you can do
Yeah, problems like these are usually solved the next day, first thing in the morning.
@Ryan happens to me everyday :)
Thanks for your help guys :) genesis + Oli Charlesworth :)
0

This Error Mostly occurs when there is a spelling mistake in the mySQL Statements, Wrong mySQL statements,Missing Semicolons or missing Any other Braces and Brackets.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.