HDFilmMaker2112 Posted June 20, 2011 Share Posted June 20, 2011 I'm having an issue redirecting my page to an error page if my UPDATE query does not find a matching entry to update: elseif($_GET['forgot']=="password"){ $new_password =& generatePassword(); $username=sanitize($_POST['username']); $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(); 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'); } elseif($num_rows1=="-1"){ header("Location: ./index.php?forgot&e=1"); } 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.'; } } mysql_affected_rows should return a positive number if it finds rows to update and -1 if the query fails. I thought if it didn't find anything to update the query would fail... should it be 0 instead of -1? Here's where the page redirects if it doesn't find anything to update. else{ $content='<div class="main"> <div class="main_header clear">Forgot Password/Username</div> <br /> <div> <p class="eighteen">Forget Password</p> <p>Enter the information below to reset your password.</p>'; if($_GET['e']=="1"){ $content.='<p class="red">Information entered incorrect.</p>'; } $content.=' <form action="./index.php?forgot=password" method="post"> <p><label>Username:</label> <input type="text" name="username" size="30" /></p> <p><label>E-Mail of Original Donation/Purchase:</label> <input type="text" name="email" size="32" /></p> <p><label>Total Donation Amount:</label> <input type="text" name="donation_amount" size="5" /> <span class="twelve">(In x,xxx.xx format. Any other format will cause an error.)</span></p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> </div> <br /> <div> <p class="eighteen">Forget Username</p> <p>Enter the information below to have your username emailed to you.</p>'; if($_GET['e']=="2"){ $content.='<p class="red">Information entered incorrect.</p>'; } $content.=' <form action="./index.php?forgot=username" method="post"> <p><label>E-Mail of Original Donation/Purchase:</label> <input type="text" name="email" size="32" /></p> <p><label>Total Donation Amount:</label> <input type="text" name="donation_amount" size="5" /> <span class="twelve">(In x,xxx.xx format. Any other format will cause an error.)</span></p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> </div> </div> <br /> '; } Quote Link to comment https://forums.phpfreaks.com/topic/239846-elseif-statement-if-mysql_affected_rows-1/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 20, 2011 Share Posted June 20, 2011 In the mysql_affected_rows documentation, a failed query means one that failed due to an error when the query was tried (sql syntax error, wrong table/column names, problem with the database connection...) Zero affected rows means that the query executed, without any errors, but no row was affected. Quote Link to comment https://forums.phpfreaks.com/topic/239846-elseif-statement-if-mysql_affected_rows-1/#findComment-1232017 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.