slotegraafd Posted December 16, 2020 Share Posted December 16, 2020 So I am trying to create a table where users can be disabled and enabled with the press of a radio button. So for the most part it works but for some reason it only allows me to disable a user it wont let me enable them and I can't seem to figure out why. I've checked that all the names were correct with the database and I have also tried both single ' quotes and double " quotes on the prepared statements to see if that makes a difference... it did not These are the functions to disable and enable users function inactive($userId){ $conn = db_connect(); $disable_user = pg_prepare($conn, 'disable', "UPDATE users SET Enabled = false, Status = 'd' WHERE Id = $userId"); $result = pg_execute($conn, 'disable', array()); } //Create a function to activate a salesperson function active($userId){ $conn = db_connect(); $enable_user = pg_prepare($conn, 'enable', "UPDATE users SET Enabled = true, Status = 'a' WHERE Id = $userId"); $result = pg_execute($conn, 'enable', array()); } $id = (array_keys($_POST['active'])[0]); $status = $_POST['active'][$id]; if($status == "t"){ active($id); } else{ inactive($id); } And this is where it gets put into action ^^ In the database I have a boolean for enabled which is either true or false and then I have a varchar for status which is either 'd' or 'a' Any help would be greatly appreciated Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/311877-why-will-only-disable-users-work-in-my-code/ Share on other sites More sharing options...
requinix Posted December 17, 2020 Share Posted December 17, 2020 What's the code for your HTML form? Specifically for the radio buttons. Quote Link to comment https://forums.phpfreaks.com/topic/311877-why-will-only-disable-users-work-in-my-code/#findComment-1583170 Share on other sites More sharing options...
slotegraafd Posted December 17, 2020 Author Share Posted December 17, 2020 11 hours ago, requinix said: What's the code for your HTML form? Specifically for the radio buttons. ope sorry if ($keys[$recordCount] == "logo" && $totalRows[$column] != "") { echo '<td class="py-2"><img src="' . $totalRows[$column] . '" alt="Client Logo" class="logo-thumbnail" /></td>'; //Check whether or not the client is active or inactive } else if ($keys[$recordCount] == "enabled") { $userId = $data[$record]['id']; $enabled = $data[$record]['status']; echo ' <td class="py-2">'. '<form method="POST" action="salesperson.php"> <div> <input type="radio" name="active[' . $userId . ']" value="Active" '; if($enabled == "a") { echo 'checked'; }; echo '/> <label for="' . $userId . '-Active">Active</label> </div> <div> <input type="radio" name="active[' . $userId . ']" value="Inactive" '; if($enabled == "d") { echo 'checked'; }; echo '/> <label for="' . $userId . '-Inactive">Inactive</label> </div> <input type="submit" name="submitType" value="Update" /> </form> Current Status: '. $totalRows[$column] . "</td>"; (its created as a function) Quote Link to comment https://forums.phpfreaks.com/topic/311877-why-will-only-disable-users-work-in-my-code/#findComment-1583191 Share on other sites More sharing options...
slotegraafd Posted December 17, 2020 Author Share Posted December 17, 2020 fixed it Quote Link to comment https://forums.phpfreaks.com/topic/311877-why-will-only-disable-users-work-in-my-code/#findComment-1583192 Share on other sites More sharing options...
requinix Posted December 17, 2020 Share Posted December 17, 2020 Good that you solved it, but next time, it would be nice if you could let us know that the problem was the code thinking the radio button's value is "t" when the form uses "Active". In case someone else comes to this thread hoping for an answer to their own problems. Quote Link to comment https://forums.phpfreaks.com/topic/311877-why-will-only-disable-users-work-in-my-code/#findComment-1583195 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.