sf_guy Posted November 2, 2012 Share Posted November 2, 2012 (edited) 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 November 2, 2012 by sf_guy Quote Link to comment https://forums.phpfreaks.com/topic/270226-session-variable-not-setting/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2012 Share Posted November 2, 2012 (edited) 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 November 2, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/270226-session-variable-not-setting/#findComment-1389804 Share on other sites More sharing options...
sf_guy Posted November 3, 2012 Author Share Posted November 3, 2012 Thanks--still learning so this is good to know. I put a hidden field on the form and set it to POST with which operation is required and it works fine now. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/270226-session-variable-not-setting/#findComment-1389813 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.