成员和访客计数器下面的代码。代码运行完美,但是当我向表active_members添加简单列(在线)时,整个代码停止工作(除了active_guests之外,这是一个单独的表)

我已经不知疲倦地尝试捕获可能导致此问题的任何内容,下面提供了表格截图。我本来要向表members_online添加一个新列(在线)即varchar,然后在下面的if SESSION中查询该新列。

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

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

$ sqlt2查询下面是我要索引新的在线列的行。

php - 我在表中添加新列后代码停止工作-LMLPHP

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>

最佳答案

将“在线”列的“默认/表达式”设置为null,希望它将起作用!

关于php - 我在表中添加新列后代码停止工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38220308/

10-16 08:46
查看更多