Hi all could someone please explain to me whats wrong with this code?...(see image for code or check bellow)
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:
Database_connec t.php
counter.php
I am running this code of an internet server. But running locally there seems to be no problem.
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:
Code:
<?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"); } ?>
Code:
$connection = mysqli_connect("localhost", "root", "jnr@mysql", "metal_traders") or die('<label>failed to connect</label>');
Code:
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>');
Comment