When I run the script it should check if the session variable is empty, if it is then give it a value.
The next time the script runs (in the same page session),
then the session variable will ofcourse not be empty meaning that the if statement should not run.
The problem is that is always runs no matter if the session variable has a value or not.
Main Script:
Expand|Select|Wrap|Line Numbers
- <?php
- session_start();
- require("database_connect.php");
- if(empty($_SESSION['counter']))
- {
- $var = $_SESSION['counter'];
- echo('<span style="color:white"> conn is ' . $var . '</span>' );
- $_SESSION['counter'] = 1;
- require_once("counter.php");
- }
- ?>
Expand|Select|Wrap|Line Numbers
- $connection = mysqli_connect("localhost", "root", "jnr@mysql", "metal_traders")
- or die('<label>failed to connect</label>');
Expand|Select|Wrap|Line Numbers
- session_start();
- $_SESSION['counter'] = 1;
- $increment = mysqli_query($connection, "update Counter set Count = Count +1 where idCounter = 1")
- or die('<label>failed to update</label>');