HDFilmMaker2112 Posted April 18, 2011 Share Posted April 18, 2011 I'm having a little issue with this script. It's returning: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/zyquo/public_html/makethemoviehappen.com/forgot_password.php on line 89" (Line 89 is: $num_rows1 = mysql_num_rows($result1) and "New password could not be generated. If you continue to have issues, please email general@makethemoviehappen.com for assistance." I checked the database and the random password generation did run, and it was inserted into the database. So it's just not detecting that it ran, so it's not sending the email. Any ideas on why? I also checked what is returned in the $result1 variable and it's the number 1. elseif($_GET['forgot']=="password"){ function &generatePassword($length=9, $strength=0) { $vowels = 'aeiuy'; $consonants = 'bcdfghjkmnpqrstwz'; if ($strength & 1) { $consonants .= 'BCDFGJLMNPQRSTVXZ'; } if ($strength & 2) { $vowels .= "AEIUY"; } if ($strength & 4) { $consonants .= '23456789'; } if ($strength & { $consonants .= '@#$%'; } $password = ''; $alt = time() % 2; for ($i = 0; $i < $length; $i++) { if ($alt == 1) { $password .= $consonants[(rand() % strlen($consonants))]; $alt = 0; } else { $password .= $vowels[(rand() % strlen($vowels))]; $alt = 1; } } return $password; } $new_password =& generatePassword(); $username=$_POST['username']; $sql="SELECT * FROM $tbl_name WHERE Username='$username' AND Email='$email' AND Amount='$donation_amount'"; $result=mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows==1){ $sql1="UPDATE $tbl_name SET Password='$new_password' WHERE Username='$username' AND Email='$email' AND Amount='$donation_amount'"; $result1=mysql_query($sql1); $num_rows1 = mysql_affected_rows($result1); if($num_rows1==1){ $content.='<p class="center">New password generated. It has been emailed to the email address provided.</p><br />'; $message='Some one (hopefully you) requested a new password be generated for your account on Make the Movie Happen. Below is the newly generated password: Password: '.$new_password.' Once you log-in, please change your password. Thank You, Make the Movie Happen Support Team '; mail($email, 'Make the Movie Happen - New Password', $message, 'From: general@makethemoviehappen.com'); } else{ $content.='New password could not be generated. If you continue to have issues, please email <a href="mailto:general@makethemoviehappen.com">general@makethemoviehappen.com</a> for assistance.'; } } else{ header("Location: ./index.php?forgot&e=1"); } } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 18, 2011 Share Posted April 18, 2011 With an INSERT/UPDATE query, you'd need to use mysql_affected_rows, not mysql_num_rows. Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted April 18, 2011 Author Share Posted April 18, 2011 Alright, tried mysql_affected_rows(); still same error, except it says: Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/zyquo/public_html/makethemoviehappen.com/forgot_password.php on line 89 (Updated first post with new code.) Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 18, 2011 Share Posted April 18, 2011 Post the revised code snippet . . . Quote Link to comment Share on other sites More sharing options...
Skewled Posted April 18, 2011 Share Posted April 18, 2011 Add your link to mysql_affected_rows($result1, $dblinkhere); You'll have to place the link that holds that connection where $dblinkhere is. Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted April 18, 2011 Author Share Posted April 18, 2011 Post the revised code snippet . . . hmm... I was using if($num_rows==1){ $sql1="UPDATE $tbl_name SET Password='$new_password' WHERE Username='$username' AND Email='$email' AND Amount='$donation_amount'"; $result1=mysql_query($sql1); $num_rows1=mysql_affected_rows($result1); I switched it to $num_rows1=mysql_affected_rows(); without $result1 inside the parenthesis and now it's working. Any idea why it wasn't working with the variable in it? And thanks by the way for the correction to mysql_affected_rows... first time I needed to calculate rows based on a database update. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 18, 2011 Share Posted April 18, 2011 I linked to the manual entry in my first reply. The explanation there is better than I can give you. Quote Link to comment Share on other sites More sharing options...
Skewled Posted April 18, 2011 Share Posted April 18, 2011 Add your link to mysql_affected_rows($dblinkhere); You'll have to place the link that holds that connection where $dblinkhere is. This is what I ment but kept the $result1 there for no reason. mysql_affected_rows() works just like that .. so whatever the last mysql_connect() database was, will be the link identifier. So on your last query $result1 was not the link identifier and that's why it flagged you with the warning. So using the mysql_affected_rows($dblinkhere); or mysql_affected_rows(); would both work. Don't forget to mark solved. 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.