未定义的变量 - PHP

时间:2011-09-09 14:09:00

标签: php mysql

我遇到了问题,我收到未定义的变量,我不确定是什么问题。我在过去3个月里只使用过PHP,所以这可能是主要的问题。

这是班级:

<?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;
}

}

?>

这是管理页面:

<?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";
?>

这是表格:

enter image description here

最后,这是错误:

enter image description here

3 个答案:

答案 0 :(得分:2)

$arrRS$arrRs不同。

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

  

PHP中的变量由美元符号后跟变量名称表示。 变量名称区分大小写。

答案 1 :(得分:1)

S应为大写

$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"];

答案 2 :(得分:0)

此错误主要发生在mySQL语句中出现拼写错误,mySQL语句错误,缺少分号或缺少任何其他大括号和括号时。