Jump to content

elseif statement if mysql_affected_rows = -1


HDFilmMaker2112

Recommended Posts

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 />
';
}

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.