AboSami
AboSami

Reputation: 259

Make the page when the visitor refresh update the field

I have a problem with mysql query ..

I have a table in the data .. name is (Info_website) , the field is (NumVisitor) ..

the problem when the visitor refresh the page I want the filed (NumVisitor + 1) but infact it +2 ..

this is the code ..

$sql2 = "UPDATE `Info_website` SET `NumVisitor` = `NumVisitor`+1 WHERE `Id`=1 LIMIT 1";
$query = mysqli_query($connect, $sql2) or die (mysqli_error());

thank you very much ..

// New Comment

<?php
require("startsession.php");
require("config.php");
include "../include/header.php";
echo '<title>'.$setting['websit_title'].' - Main Page </title>';
?>
<br />
<br />
<table align="center" width="65%">
<tr>
    <td class="head_title" colspan="4">Information</td>
</tr>
<tr>
    <td width="35%">Number of New Book:</td>
    <td>
        <?php
            $sql = "SELECT IDkalemat FROM main_kalemat";
            $query = mysqli_query ($connect , $sql) or die (mysqli_error());
            $num = mysqli_num_rows($query);
            echo $num;
        ?>      
    </td>

    <td width="35%">Number of Users:</td>
    <td>
        <?php
            $sql = "SELECT IDUser FROM user_kalemat";
            $query = mysqli_query ($connect , $sql) or die (mysqli_error());
            $num = mysqli_num_rows($query);
            echo $num;
        ?>
    </td>
</tr>
        <tr>
        <td width="35%">Number Of Visitors:</td>
    <td>
        <?php
            $sql = "SELECT NumVisitor FROM Info_website";
            $query = mysqli_query ($connect , $sql) or die (mysqli_error());
            $num = mysqli_fetch_array($query);
            echo $num['NumVisitor'];
        ?>
    </td>
</tr>

</table>

<br />
<br />
<?php

//-------- from here the number of visitor

//--------- the end
$sql2 = "UPDATE Info_website SET NumVisitor = NumVisitor+1 WHERE Id=1 LIMIT 1"; 
$query = mysqli_query($connect, $sql2) or die (mysqli_error());
if ($query)
{
    echo '1';
}else{
    echo '0';
}
include ("../include/footer.php");
?>

Upvotes: 0

Views: 112

Answers (1)

David
David

Reputation: 218847

It sounds like this code is being executed twice on each page visit. Can you show us the rest of the code as well?

Upvotes: 1

Related Questions