SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with re-direct - header output etc

    I have a problem with my "password recover" script.

    I have a form to fill in the email address on one page and when you submit it to go to the password recover page, I get an error ONLY when there are NO rows returned from the database and a "header already sent" error as well.

    It only works when there is an email address match in the database. Then there are no errors and the re-direct works without problem.

    This script works on other servers, but this problem is on Godaddy.com.

    I wonder if someone could take a look at it and let me know if there is a way to go around it.
    Again, there is only a problem when there is no match of email address in the database.

    Here are part of the errors I get:

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/content.......

    Warning: Cannot modify header information - headers already sent by (output started at /home/content
    ...../find_password.php:32)
    in /home/content...../find_password.php on line 48

    FORM PAGE

    <FORM METHOD="POST" ACTION="find_password.php">
    <input name="email" type="text" />
    <input type="submit" name="Submit" value="Submit" />
    </FORM>

    RECOVER PASSWORD PAGE

    PHP Code:

    <?php 

    $link 
    mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
        if(!
    $link) {
            die(
    'Failed to connect to server: ' mysql_error());
        }
        
        
    //Select database
        
    $db mysql_select_db(DB_DATABASE);
        if(!
    $db) {
            die(
    "Unable to select database");
        }

        
    //Function to sanitize values received from the form. Prevents SQL injection
        
    function clean($str) {
            
    $str = @trim($str);
            if(
    get_magic_quotes_gpc()) {
                
    $str stripslashes($str);
            }
            return 
    mysql_real_escape_string($str);
        }

    $email clean($_POST['email']);


    $QUERY mysql_query("SELECT * FROM members WHERE email='$email'");
    $ROWS mysql_num_rows($QUERY);

    $MyPsswd mysql_result($QUERY,$I,"password");
    $MyUser mysql_result($QUERY,$I,"username");

    if (
    $ROWS) {

    ini_set("sendmail_from""info@domain.com");
    ini_set("SMTP""mail.domain.com");

    $address $email;
    $email2 "info@domain.com";
    $subject "* * Login Details Recover * *";
    $body "Login Details Recover\r\n\r\nGreetings,\r\nHere are you login details. Contact us if you require any further assistance.\r\n\r\nPassword: $MyPsswd\nUser: $MyUser\n";

    $mailsend mail("$address","$subject","$body","From: Website Administrator <$email2>");
    header("Location:success.php");
    } else {
    header("Location:email_error.php");
    exit;
    }
    ?>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure $ROWS is 1 before trying to use mysql_result.

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do I do that. can you show an example in the code?

    thanks

  4. #4
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I fixed it. Thanks for your help. It worked great.

  5. #5
    SitePoint Addict eanimator's Avatar
    Join Date
    Sep 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use ob_start()


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
  •