SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I must be really stupid... I have a page that allows a user to change his/her password and/or e-mail address in a database (MySQL in this case). But for some reason, when the user submits the form, the original value for ONE of the fields (not the changed value) is what gets passed to the handling script. The code for the change page is as follows - I've changed some names to protect the innocent. :-D

    <html>
    <head>
    <title>Administer Your Account</title>
    <link rel="stylesheet" href="styles/main.css" type="text/css">
    </head>
    <body bgcolor="#000000">
    <h1>Administer Your Account</h1>
    <?php
    $sql="SELECT username, password, email FROM table_name WHERE uid = '$uid'";
    $result=mysql_query($sql);
    if(!$result) {
    echo("<p>Error accessing the user database: " . mysql_error() . "</p>\n");
    include($DOCUMENT_ROOT . "/../includes/exit.inc");
    }
    $username=mysql_result($result,0,0);
    $password=mysql_result($result,0,1);
    $email=mysql_result($result,0,2);
    ?>
    <form name="userform" action="user_admin2.php" method="post">
    <input type="hidden" name="uid" value="<?php echo($uid); ?>">
    <h3>User Name: <?php echo($username); ?></h3>
    <p>Your Email Addressbr>
    <input type="text" name="email" value="<?php echo($email); ?>" size="20" maxlength="40"></p>
    <p>Your Passwordbr>
    <input type="password" name="password" value="<?php echo($password); ?>" size="20" maxlength="40"></p>
    <input type="submit" value="Submit" name="B1">
    </form>
    <?php

    include($DOCUMENT_ROOT . "/../includes/menu.inc");
    include($DOCUMENT_ROOT . "/../includes/footer.inc");

    ?>
    </body>
    </html>

    Now here's the code for the handling page:

    <html>
    <head>
    <title>Administer Your Account</title>
    <link rel="stylesheet" href="styles/main.css" type="text/css">
    </head>
    <body bgcolor="#000000">
    <?php include($DOCUMENT_ROOT . "/../includes/page_header.inc"); ?>
    <h1>Administer Your Account</h1>
    <?php
    if($email && $password && $username && $uid) {
    $sql="UPDATE auth_user SET email = '$email', password = '$password' WHERE uid = '$uid'";
    echo($sql);
    }
    include($DOCUMENT_ROOT . "/../includes/menu.inc");
    include($DOCUMENT_ROOT . "/../includes/footer.inc");
    ?>
    </body>
    </html>

    The change page looks just like it should, with the values from the database set as the initial values. But when I change the e-mail address and the password, the new password is reflected by the handling page, but not the new e-mail address... it shows the ORIGINAL e-mail address.

    Any ideas? Thanks!

  2. #2
    SitePoint Guru DenverDave's Avatar
    Join Date
    Feb 2001
    Location
    Denver, Colorado
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm just shooting in the dark here, but this may help keep you intertained, until someone who knows the answer responds. I am used to ColdFusion, where have to (or should be) very specific for the source of each variable (url, form, local). Might try testing the $HTTP_POST_VARS("variable") (hope I have this syntax somewhat close) rather than just the variable on your destination form to make sure that you are picking oup the variable you think you are. I've been fooled by this before.

    Good luck and be sure to post your solution.
    Dave

  3. #3
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could be right. To test this, on the change form, instead of using PHP to fill in the e-mail field with the $email variable, I hard-coded an e-mail address into the field but left everything else the same. Now when I submit the form, the handling script reads not the changed e-mail address, and not the hard-coded e-mail address, but the e-mail address that was retrieved from the database (and not used!) in the script containing the change form! Also, I tried changing the name of the variable (from $email to something else) and THEN it works. But I still don't understand why it's doing that, and I've never encountered the problem before. Plus I don't understand why it does it for the e-mail field and not the password field!

    Anyone?

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am having a hard time believing that the email is just getting sent as the value from the db when you hardcode a different email address in the form. Is this your complete code? Is there any queries in the included files that might be retreiving and setting the value of $email and thus killing the value sent from the form, like inside of

    <?php include($DOCUMENT_ROOT . "/../includes/page_header.inc"); ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Antoher trick you can use to see exactly which variables are coming from the form:

    PHP Code:
    while(list($key,$val) = each($HTTP_POST_VARS)) {
    print 
    "$key = $val<br>";

    So if you run that and the vars are coming through correctly then something in your change script is mucking it up above the query.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You know, I thought of that, and I checked all of the includes earlier. It's not so much that the wrong value is getting passed to the handling script, but that the handling script is picking up the value from another source. So I went back to double-check all of the includes... AHA! What I missed on the first time around was that there was an include WITHIN one of the includes, and when I checked THAT one, there was the problem! I had resolved the issue by simply renaming the variable, but knowing me I would have lost sleep wondering why this problem was happening. Now I don't have to. THANK YOU.

  7. #7
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, looks like we "crossed in the mail". Thanks for the additional trick/tip.

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pesky Includes

    As a rule of thumb I never nest includes, ie(I never use an include within an include), doing so can make you wander down a dark and uncharted path trying to debug your scripts.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •