pyrodude Posted August 7, 2007 Share Posted August 7, 2007 So, I have the following code and it works fine unless I try to update the information. It will cancel, delete, display, etc just fine, but when I click Submit Changes it just sits forever and ever. However, when I manually go to another screen and go back and display the information, the changes have been made. In the case of a password mismatch, it also just sits there, but $_SESSION['sendmessage'] is set and will display on the next page. Maybe this is more of a header issue. I'm not really sure. The code is as follows, if something's not clear, let me know. <?php require_once("../dblogin.php"); if (mysqlVerifyLogin($_SESSION['username'],$_SESSION['password']) == FALSE) { unset($_SESSION); session_destroy(); header("Location: ../login.php"); } if (isset($_POST['delete'])) { // Delete id number $_POST['id'] if ($_SESSION['username'] !== $_POST['oldusername']) { $id = $_POST['id']; mysql_select_db("$dbAdminDatabase") or die("Unable to select database"); $query = "DELETE FROM $dbAdminTable where id='$id' LIMIT 1"; $result = mysql_query($query); $_SESSION['sendmessage'] = "<h1>User number $id has been successfully deleted.</h1>"; } else { // Trying to delete own account $_SESSION['sendmessage'] = "<h1>Unable to delete your own account.</h1>"; } header("Location: ../admin.php"); } if (isset($_POST['cancel'])) { unset($_SESSION['editline']); header("Location: ../admin.php"); } if (isset($_POST['id'])) { $id = $_POST['id']; $newusername = $_POST['newusername']; $newpassword1 = mysql_real_escape_string($_POST['newpassword1']); $newpassword2 = mysql_real_escape_string($_POST['newpassword2']); $newrole = $_POST['newrole']; // The form has been submitted for a change mysql_select_db("$dbAdminDatabase") or die("Unable to select database"); if (strlen($newpassword1)>0) { if ($newpassword1 == $newpassword2) { $newpassword = crypt($newpassword1,"bC"); $query = "UPDATE $dbAdminTable SET username='$newusername', password='$newpassword', role='$newrole' WHERE id='$id' LIMIT 1"; $result = mysql_query($query); header("Location: ../admin.php"); } else { $_SESSION['sendmessage'] = "Passwords do not match."; header("Location: ../admin.php"); } } else { $query = "UPDATE $dbAdminTable SET username='$newusername', role='$newrole' WHERE id='$id' LIMIT 1"; $result = mysql_query($query); header("Location: ../admin.php"); } } if (isset($_SESSION['editline'])) { $id = $_SESSION['editline']; unset($_SESSION['editline']); mysql_select_db("$dbAdminDatabase") or die("Unable to select database"); $query = "SELECT * FROM $dbAdminTable where id='$id' LIMIT 1"; $result = mysql_query($query); $numrows = mysql_numrows($result); $i = 0; $username = mysql_result($result, $i, "username"); $password = mysql_result($result, $i, "password"); $role = mysql_result($result, $i, "role"); $userid = mysql_result($result, $i, "id"); include("../includes/dgnw_admin_header.inc"); ?> <fieldset><legend><?php echo "User ID #$userid"; ?></legend> <form method=post> <table border=0> <tr> <td>Username: </td> <td><input type="text" name="newusername" value="<?php echo $username; ?>" /><input type="hidden" name="oldusername" value="<?php echo $username; ?>" /></td> </tr> <tr> <td>Password: </td> <td><input type="password" name="newpassword1" /><input type="hidden" name="oldpassword" /></td> </tr> <tr> <td>Confirm Password: </td> <td><input type="password" name="newpassword2" /></td> </tr> <tr> <td>Role:</td> <td><select size=1 name="newrole"> <option value="admin"<? if ($role == "admin") { echo " Selected='selected'"; } ?>>Administrator</option> <option value="superuser"<? if ($role == "superuser") { echo " Selected='selected'"; } ?>>Superuser</option> </select><input type="hidden" name="oldrole" value="<?php echo $role; ?>" /></td> </tr> </table><br /> <input type="submit" name="cancel" value="Cancel" style="float:right;" /> <input type="submit" name="submit" value="Submit Changes" /> OR <input type="submit" name="delete" value="Delete '<?php echo $username; ?>'" /> <input type="hidden" name="id" value="<?php echo $userid; ?>" /> </form></fieldset> <?php include("../includes/dgnw_footer.inc"); } else { header("Location: ../admin.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/63675-might-be-a-mysql-error/ Share on other sites More sharing options...
play_ Posted August 7, 2007 Share Posted August 7, 2007 Just a show in the dark. When the header redirects you to ../admin.php, make sure admin.php isn't redirecting you back. I've done this before, hehe. I had an IF statement in the page what would redirect me, and i'd get redirected back and forth. Quote Link to comment https://forums.phpfreaks.com/topic/63675-might-be-a-mysql-error/#findComment-317335 Share on other sites More sharing options...
pyrodude Posted August 7, 2007 Author Share Posted August 7, 2007 Now, I have my redirects occurring based on the presence of certain session variables, but does it not matter? I never thought I was ending up in an infinite loop...makes sense though! Quote Link to comment https://forums.phpfreaks.com/topic/63675-might-be-a-mysql-error/#findComment-317351 Share on other sites More sharing options...
play_ Posted August 7, 2007 Share Posted August 7, 2007 Usually when the page just sits there, it means it's stuck in an infinite (or really long) loop. Since you dont have any loops in the code you posted, it maybe be that each page is sending you back and forth Quote Link to comment https://forums.phpfreaks.com/topic/63675-might-be-a-mysql-error/#findComment-317530 Share on other sites More sharing options...
pyrodude Posted August 7, 2007 Author Share Posted August 7, 2007 So, I changed the code so that it redirects to a nonexistant page and all it's doing is just sitting there. I don't get a page not found error or anything. Could something be wrong with my headers? It seems to work fine on all my other pages, just not this one for some reason... Quote Link to comment https://forums.phpfreaks.com/topic/63675-might-be-a-mysql-error/#findComment-317639 Share on other sites More sharing options...
dbo Posted August 7, 2007 Share Posted August 7, 2007 Comment out the redirects all together and replace them with some sort of an echo statement so you can trace your code. You'll be able to find out where it gets in execution for dying... once you know this you can make some better guesses as to what is causing the problem. Quote Link to comment https://forums.phpfreaks.com/topic/63675-might-be-a-mysql-error/#findComment-317645 Share on other sites More sharing options...
pyrodude Posted August 7, 2007 Author Share Posted August 7, 2007 So, the issue seems to revolve around unsetting $_SESSION['editline']. I don't use it for anything but to get the userid that is being edited, so I changed it to unset when the mysql has been completed and then redirect, and that's when it hangs. If I leave it set (such as when attempting to change the passwords and there's a mismatch) it reloads just fine with the error message, but if I unset($_SESSION['editline']);, it winds up just hanging there, regardless of what page I try to redirect to. Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/63675-might-be-a-mysql-error/#findComment-317673 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.