Page 1 of 1
forgot password
Posted: Tue Sep 14, 2004 10:08 am
by robjime
Code: Select all
<?php
$button = $_POST['send'];
$name = $_POST['name'];
$email = $_POST['email'];
if(isset($button)) {
include('config.php');
$connection = mysql_connect($dblocal, $user, $passwrd) or die(mysql_error());
mysql_select_db($database, $connection) or die(mysql_error());
$query = "SELECT * FROM users
WHERE user='$name' AND email='$email' ";
$result = mysql_query($query, $connection) or die('error making query');
$affected_rows = mysql_num_rows($result);
if($affected_rows == 1) {
echo "Your password has been sent to your email. <a href='login.php'>Click Here to login</a>";
}
else {
echo 'Unable to find selected username or email <a href="forgot.php">Click Here to try again</a>';
}
}
else {
echo '<table border=0>';
echo '<tr><td>Username:</td><td><input name="name" type="input"></td></tr>';
echo '<tr><td>Email:</td><td><input name="email" type="input"></td></tr>';
echo '</table>';
echo '<input name="send" type="submit" id="send" value="Go"> ';
echo '<input name="Clear" type="reset" id="Clear" value="Clear">';
}
?>
So how do i pull the users password out of the same row as the users name and password or even assign them a new one?
Posted: Tue Sep 14, 2004 10:14 am
by m3mn0n
You do this by writing code.
Seriously though you selected * (which means all) so any column in that row of the table is accessable to you in the array you need to fetch.
See: [php_man]mysql_fetch_array[/php_man]()
Once you fetch an array, you can access the values of the columns of that row by something like
$fetched_array['user'] and
$fetched_array['pass'].
Re: forgot password
Posted: Tue Sep 14, 2004 10:15 am
by qads
Code: Select all
$button = $_POST['send'];
$name = $_POST['name'];
$email = $_POST['email'];
if(isset($button)) {
include('config.php');
$connection = mysql_connect($dblocal, $user, $passwrd) or die(mysql_error());
mysql_select_db($database, $connection) or die(mysql_error());
$query = "SELECT * FROM users
WHERE user='$name' AND email='$email' ";
$result = mysql_query($query, $connection) or die('error making query');
$affected_rows = mysql_num_rows($result);
if($affected_rows == 1) {
$user_info = mysql_fetch_array($result);//info is in this array
echo "Your password has been sent to your email. <a href='login.php'>Click Here to login</a>";
}
else {
echo 'Unable to find selected username or email <a href="forgot.php">Click Here to try again</a>';
}
}
else {
echo '<table border=0>';
echo '<tr><td>Username:</td><td><input name="name" type="input"></td></tr>';
echo '<tr><td>Email:</td><td><input name="email" type="input"></td></tr>';
echo '</table>';
echo '<input name="send" type="submit" id="send" value="Go"> ';
echo '<input name="Clear" type="reset" id="Clear" value="Clear">';
}
check line 13.