将新的colunm添加到Table后,代码停止工作

时间:2016-07-06 09:14:23

标签: php mysql

会员和来宾柜台下面的代码。代码运行完美但是当我向表中添加一个简单的列(在线)active_members时,整个代码停止工作(除了active_guests,因为这是一个单独的表)

我已经孜孜不倦地试图抓住可能导致这种情况的任何事情我已经包含了下面的表截图。我想在表member_online中添加一个varchar的新列(在线),然后在下面的if SESSION中查询该新列。

为什么代码停止工作,有人可以看到原因或解决方案吗?

一旦删除在线专栏,代码就会再次运行完美。

下面的 $ sqlt2查询是我要为新在线专栏编制索引的行。

enter image description here

include('..\db.php');
$con = mysqli_connect($dbsrvname, $dbusername, $dbpassword, $dbname);

 //declare variables
$guest_timeout = time() -1 * 60;
$member_timeout = time() -1 * 60;
$guest_ip = $_SERVER['REMOTE_ADDR'];
$time = time();

 // if the session is set PUTS THE USER IN MEMBERS TABLE
if(isset($_SESSION['CurrentUser'])){

    //if user is logged in

    $sqlt = mysqli_query($con,"DELETE  FROM active_guests WHERE guest_ip='".$guest_ip."'");



   **//I WANT TO ADD TO THE ONLINE COLUMN AND REPLACE A SIMPLE STRING INTO ONLINE**
    $sqlt2 = mysqli_query($con,"REPLACE INTO active_members VALUES ('".$_SESSION['CurrentUser']."','".$time."')");
    $name = $_SESSION['CurrentUser']  ;





}else{

    //if user not in a session PUTS THE USER IN GUESTS TABLE
    $sqlt3 = mysqli_query($con,"REPLACE INTO active_guests (guest_ip,time_visited)VALUES ('".$guest_ip."','".$time."')");



}

 //execute querys
$sqlt4 = mysqli_query($con,"DELETE  FROM  active_guest WHERE time_visited < ".$guest_timeout);
$sqlt5 = mysqli_query($con,"DELETE  FROM  active_members WHERE time_visited < ".$member_timeout);
$sqlt6 = mysqli_query($con,"SELECT guest_ip FROM active_guests");
$sqlt7 = mysqli_query($con,"SELECT username FROM active_members");
$online_guests = mysqli_num_rows($sqlt6);
if(isset($_SESSION['CurrentUser'])){


$sqlt7 = mysqli_query($con,"SELECT username FROM active_members");

if($sqlt7->num_rows){
            while($row = $sqlt7->fetch_object())
            {
            echo '<pre>',$row->username,'</pre>' ;

            }
            //$result->free();
        }
}else{
    echo "Login  to see members-online list";

}
$online_members = mysqli_num_rows($sqlt7);


?>

 // display results
<div class="container">
<p>_________________________</p>
<p>online Guests : <?php echo $online_guests ; ?></p>
<p>online Members : <?php  echo $online_members ; ?></p>

</div>

1 个答案:

答案 0 :(得分:0)

设置列&#34;在线&#34; s&#34;默认/表达&#34;为了null,希望它会起作用!