Jump to content

[SOLVED] Forgot password script problem


mjgdunne

Recommended Posts

Hi i have this forgot password script which asks the user for their email address and username and if they are correct their details will be sent to their email address which they are registered with.

Forgot.html

<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=30%>
<tr>
<TD ALIGN=CENTER VALIGN=TOP WIDTH=50>
</TD>
<TD ALIGN=LEFT VALIGN=TOP WIDTH=83%>
</TABLE>
<TABLE BGCOLOR="#F0F8FF" WIDTH=30%>
<TR><TD ALIGN="center">


<p><b>Forgot your password?</b> Enter your
email address and user name below, and we will email you a new password.<br>
<i>Please use the email address you provided when you
registered. </i></p>
<form action="forgotpassword.php" method="post">

Email: <input type="text" name="myemail" id="myemail"><br />

Username: <input type="text" name="myusername" id="myusername"><br />

<br /><br />

<input type="hidden" name="command" value="forgot">
<input type="submit" value="Send password">

</form>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

 

Checklogin.php

<?php

session_start();

ini_set( 'display_errors', '1' );
error_reporting ( 2047 );


$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "root", "root")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];



$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);
if($result === false){
    exit('db error: ' . mysql_error());
}


// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// assign $_SESSION variables: $myusername, $mypassword and redirect to file "login_success.php"

    $userdata = mysql_fetch_row($result); //get the user row
    $_SESSION["myusername"] = $myusername;
    $_SESSION["mypassword"] = $mypassword;
$_SESSION["mylevel"]    = $mylevel;

    $debug = true; // Turn on DEBUGGING
    if($debug){
        //for debug only
        echo 'myusername: ' . $_SESSION["myusername"] . "<br />\n";
        echo 'mypassword: ' . $_SESSION["mypassword"] . "<br />\n";
        echo 'mylevel : '   . $_SESSION["mylevel"] . "<br />\n";
        exit();
    }

    header("location:login_success.php");

}

else {
    header("location:login_failure.php");
    // echo "Wrong Username or Password";
}
exit();

?>

Link to comment
Share on other sites

Sorry just realised i left out the whole question part, ok this is the code i have put together for a forgot password if the user enters incorrect details - they are asked for email add and username these are checked in the database and if they exist an email containing all of their details username password etc is sent to the email address entered, my problem is its not working.... i am getting an error :

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\forgotpassword.php on line 51

Any help would be great?

Link to comment
Share on other sites

Unfortunately, I'm good with PHP, not so much with Mercury mail. I just set it up, and fix the problems as I see them with that program. I think the problem is no longer PHP-based, but Mercury based. I reccomend you go to his website and get some help for setting it up. sorry again.

 

Jon

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.