Jump to content

Session Variable Not Setting


sf_guy

Recommended Posts

I have a form where a superuser can add a new regular user, or edit or delete the information for a regular user. To make deleting harder, they have to type the word "CONFIRM" in a box to cause the delete to occur.

 

The javascript validation for lengths, dupes, etc. is all working fine, but this last bit of code is not (I realize I could just have the .submit() once in the code block but moved it because I thought that might be the issue (apparantly it isn't). INSERT and UPDATE work fine, but DELETE is never seen for some reason.

 

 

if (passesvalidation == "true") {

if (v_insert == "TRUE" {

// Set header

alert('DEBUG: Insert Confirmed');

<?PHP $_SESSION['header']='New User Successfully Added"; ?>

<?PHP $_SESSION['data_action']='INSERT;?>

document.forms["useredit"].submit();

} else {

if (v_delete == "CONFIRM") {

// Set header

alert('DEBUG: Delete Confirmed');

<?PHP $_SESSION['header']='User Successfully Deleted'; ?>

<?PHP $_SESSION['data_action']='DELETE';?>

document.forms["useredit"].submit();

} else {

// Set header

alert('DEBUG: Update Confirmed");

<?PHP $_SESSION['header']='User Information Changed Successfully'; ?>

<?PHP $_SESSION['data_action']='UPDATE';?>

document.forms["useredit"].submit();

}

}

}

 

On the submission form, I have the following:

 

switch ($_SESSION['data_action']) {

case "INSERT":

$query = "INSERT INTO userlist VALUES '$userid','$firstname','$lastname',$usertype,'$pw','$email','2025-12-31')";

break;

case "UPDATE":

// if the password reset button is checked, then reset user's password

if (isset($_POST['fld_resetpassword'])) {

$query = "UPDATE userlist

SET firstname = '$firstname',

lastname = '$lastname',

usertype = '$usertype',

pw = '$pw',

email = '$email'

WHERE userid = '$userid'";

} else { // otherwise don't change the password

$query = "UPDATE userlist

SET firstname = '$firstname',

lastname = '$lastname',

usertype = '$usertype',

email = '$email'

userid = '$userid'";

}

break;

case "DELETE":

$query = "DELETE FROM userlist WHERE userid = '$userid'";

break;

}

 

INSERT works fine.

UPDATE works fine.

DELETE displays the message "ALERT: DEBUG Delete Confirmed" but then, on the PHP page, the output is:

 

DEBUG: ----------> Data action ------------> UPDATE

DEBUG: ----------> QUERY ------------> UPDATE userlist SET firstname = '... etc. etc.

 

The code is definitely recognizing that it's a delete because the DELETE alert is being triggered, but why isn't the "<?PHP $_SESSION['data_action']='DELETE'; ?>" setting being honored and instead being seen/set as "UPDATE"?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/270226-session-variable-not-setting/
Share on other sites

The three blocks of PHP code you have in amongst the javascript logic ALL runs on the server when the page is first requested. So, the two session variables will always have the last two values that are being set.

 

You would need to submit a value with the form that indicates what operation to perform.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.