SauloA Posted February 20, 2007 Share Posted February 20, 2007 I'm trying to create a form that will that will send a user their password through an email. The user is supposed to put their username in the text box and than get an email with their login information. Here's my code. The problem seems to be this code. I'd appreciate the help. mysql_select_db($database_connBlog, $connBlog); $sql="SELECT user_pass, user_email FROM user_tbl WHERE user_sname='".$user_sname."'"; $r = mysql_query($sql, $connBlog); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_affected_rows()==0){ print "no such login in the system. please try again."; exit(); } else { $row=mysql_fetch_array($r); $password=$row["user_pass"]; $email=$row["user_email"]; $subject="your password"; $header="from:you@yourdomain.com"; $content="your password is ".$password; mail($email, $subject, $row, $header); print "An email containing the password has been sent to you"; } Here's the form where the usename is inputted. <form name="forgot" method="post" action="forgot.php"> <input name="sname" type="text" value="user_sname" size="20"/><br /> <input type="submit" name="submit" value="submit"/> <input type="reset" name="reset" value="reset"/> </form> If this isn't a good way of sending login information. Can someone send me in the right dircetion? Quote Link to comment Share on other sites More sharing options...
trq Posted February 20, 2007 Share Posted February 20, 2007 What exactly is the problem? You are yet to ask a question. Quote Link to comment Share on other sites More sharing options...
SauloA Posted February 20, 2007 Author Share Posted February 20, 2007 I don't know what the problem is. I'm assuming that there's somthing wrong with my code. Maybe somebody can tell me what's missing or how to fix it. Quote Link to comment Share on other sites More sharing options...
trq Posted February 20, 2007 Share Posted February 20, 2007 What is the symptoms of your problem? What isn't happening that you expect to happen? Quote Link to comment Share on other sites More sharing options...
SauloA Posted February 20, 2007 Author Share Posted February 20, 2007 The part of my code that says: if(mysql_affected_rows()==0){ print "no such login in the system. please try again."; exit(); is working is displaying "no such login in the system. please try again." as it should display if there is an error. I don't know what the error is though. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 Well for one there is no function called that... Quote Link to comment Share on other sites More sharing options...
trq Posted February 20, 2007 Share Posted February 20, 2007 mysql_affected_rows() only works with queries which actually alter records not SELECT statements. Your code might look more like.... <?php mysql_select_db($database_connBlog, $connBlog); $sql="SELECT user_pass, user_email FROM user_tbl WHERE user_sname='".$user_sname."'"; if (!$r = mysql_query($sql, $connBlog)) { $err=mysql_error(); print $err; exit(); } if (!mysql_num_rows()){ print "no such login in the system. please try again."; exit(); } $row=mysql_fetch_array($r); $password=$row["user_pass"]; $email=$row["user_email"]; $subject="your password"; $header="from:you@yourdomain.com"; $content="your password is ".$password; if (mail($email, $subject, $row, $header)) { print "An email containing the password has been sent to you"; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 20, 2007 Share Posted February 20, 2007 Well for one there is no function called that... Um... Yes there is. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 Weird...when I looked it up in the manual to check the arguments, it redirected me to mysqli_affected_rows - over and over again. Now it's not doing it...wtf was I doing? Quote Link to comment Share on other sites More sharing options...
SauloA Posted February 20, 2007 Author Share Posted February 20, 2007 There's still an error with: if (!mysql_num_rows()){ print "no such login in the system. please try again."; exit(); } in your code thorpe. Quote Link to comment Share on other sites More sharing options...
SauloA Posted February 20, 2007 Author Share Posted February 20, 2007 Instead of trying to get this code to work, can somebody tell me or redirect me somewhere that shows how send a user their password through an email if the user forgets their login information. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.