I have a form that will go through AJAX to set a session variable and back to the original page.
My problem is that I cannot set the session variable, thus, it is not working.
my main PHP page
<?php
if ($_SESSION['adminFunction'] == 'adminfunction'){
echo "<form id='userOptionRequest' action='request.php'>";
echo "<button name='adminFuncUserOption' onclick='adminFuncOption(1)'>User Option</button> <br /> <br />";
echo "<button name='adminFuncUserOption' onclick='adminFuncOption(2)'>Subject Option</button> <br /> <br />";
echo "<button name='adminFuncUserOption' onclick='adminFuncOption(3)'>Test Option</button> <br /> <br />";
echo "</form>";
}
if ($_SESSION['adminFunction'] == 'addusers'){
echo "hello world";
}
?>
my JS file
function adminFuncOption(option){
if (option == 1){
var userOptionRequest = new XMLHttpRequest();
userOptionRequest.open('POST','request.php',false);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
userOptionRequest.send('adminFuncUserOption=' + option);
return(1);
} }
the request.php
<?php
session_start();
$option = $_POST['option'];
if ($option != NULL){
if ($option == 1){
$_SESSION['adminFunction'] = 'addusers';
header('Location: http://rsc_naga_isd/admin');
}
}
var_dump($_POST);
var_dump($_SESSION);
var_dump($_GET);
?>
when I go back to my main PHP page, the session should now be addusers and should display 'hello world'
I have research but still had a hard time understanding AJAX or PHP Submitting HTML form using Jquery AJAX http://www.ajax-tutor.com/post-data-server.html http://tutorialzine.com/2009/09/simple-ajax-website-jquery/
Oh, am still not familiar with jquery and still new to javascript, but would prefer javascript before diving in to jquery.