Jump to content

Might be a MySQL error?


pyrodude

Recommended Posts

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");
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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? 

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.