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

Edited by sf_guy
Link to comment
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.

Edited by PFMaBiSmAd
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.