Im new to php and javascript so please bear with me.
index.php:
<?php
$_SESSION['test'] = 1;
?>
<div>
<?php echo "Before: " . $_SESSION['test']; ?>
<input type="submit" value="CLICK" onclick="<?php $_SESSION['test'] = 0; ?>;" />
<?php echo "After: " . $_SESSION['test']; ?>
</div>
Why is it that $_SESSION['test'] is already 0 when I haven’t clicked the button yet??? Please help me…
PHP is a preprocessor. Everything you write in PHP is executed BEFORE the page is presented, while javascript executes clientside as the page is running. Therefore, you cannot set a PHP value with a javascript event.