PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
robjime
Forum Commoner
Posts: 46 Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO
Post
by robjime » Tue Sep 14, 2004 10:08 am
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?
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Tue Sep 14, 2004 10:14 am
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'] .
qads
DevNet Resident
Posts: 1199 Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane
Post
by qads » Tue Sep 14, 2004 10:15 am
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.