| FigMaDesign 2004-08-18, 3:57 pm |
| Hi everyone :D
As you can see i dont know so much of PHP =)
I´ve got a problem as i hope someone will be able to help me with.
This is a free script and didnt include a lost password part.
I whant my users to be able to rechive there password with a form.
This is the registration:
<?php
session_start(); // On top
include "conn.php"; // Database
if (isset(_POST['submit'])){
// Remove spaces before/after
foreach(_POST as key => val){
_POST[key] = trim(val);
}
//Check empty fields
if (empty(_POST['user']) ||
empty(_POST['passwd']) ||
empty(_POST['name']) ||
empty(_POST['email'])) {
reg_error[] = 0;
}
// Check if username exist
sql = "SELECT COUNT(*) FROM members WHERE
user='{_POST['user']}'";
result = mysql_query(sql);
if (mysql_result(result, 0) > 0) {
reg_error[] = 1;
}
// Check email
if
(!preg_match('/^[-A-Za-z0-9_.]+[@][A-Za-z0-9_-]+([.][A-Za-z0-9_-]+)*[.][A-Za-z]{2,8}/',
_POST['email'])) {
reg_error[] = 2;
}
// No errors? Save and login!
if (!isset(reg_error)) {
sql = "INSERT INTO members(user, pass, name, email)
VALUES('{_POST['user']}',
'{_POST['passwd']}',
'{_POST['name']}',
'{_POST['email']}')";
mysql_query(sql);
_SESSION['sess_id'] = mysql_insert_id();
_SESSION['sess_user'] = _POST['user'];
header("Location: default.php");
exit;
}
} else {
// Vars for empty fields
for (i=0; i<4; i++) {
back[i] = "";
}
}
error_list[0] = "You didnt complete the form";
error_list[1] = "Username taken";
error_list[2] = "Your email doesnt work";
?>
Thats the register part.
Now i need a lost password part
<form action="default.php?section=lostpw"
method="post">
<table width="300" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td width="100" align="right"
valign="middle">Username: </td>
<td><input name="user"
type="text" id="user"></td>
</tr>
<tr>
<td align="right"
valign="middle">Mail:</td>
<td><input name="email"
type="text" id="email"></td>
</tr>
<tr>
<td> </td>
<td><input name="submit2"
type="submit" value="Get password"></td>
</tr>
</table>
</form>
and when they press submit i whant a mail to be sent to them where the
password is shown. (If username and email was found in database)
Please help me! :D
PHP to the limit =)
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
|