Jump to content

Archived

This topic is now archived and is closed to further replies.

Tandem

Not sure why...

Recommended Posts

I'm writing a script so that members can change their passwords.
I'm starting the script by checking the form for errors. The first error i'm checking for is empty fields. This below script does this semi-successfully. It prints out that an error has occurred and what the errors are depending on which field is empty. The problem is that it always prints out that there has been an error, even if all the feilds have been filled in.

[code]<?php
session_start();
include 'db.php';
include 'session_check.php';

$current_pass = $_POST['current_pass'];
$new_pass = $_POST['new_pass'];
$confirm_pass = $_POST['confirm_pass'];

//Checking for empty fields
if ((empty($current_pass)) || (empty($new_pass)) || (empty($confrim_pass))) {
echo '<div class="error">*The following errors occurred:</div>' . "\n";

if (empty($current_pass)) {
echo '<div class="error">You did not specify your Current Password</div>' . "\n";
}

if (empty($new_pass)) {
echo '<div class="error">You did not specify your New Password</div>' . "\n";
}

if (empty($confirm_pass)) {
echo '<div class="error">You did not Confirm your New Password</div>' . "\n";
}
include 'Account_Manager.php';
exit();
}
?>[/code]

Can any tell me why, and how to fix it?

Thanks in advance.

-Tandem

Share this post


Link to post
Share on other sites
if((!$username) || (!$password) || (!$number))
{
     
if(!$username)
{
$error .= "<tr><td>You have not entered your username.</td></tr>"; 
}     
if(!$password)
{
$error .= "<tr><td>You have not entered your password.</td></tr>";
}
if(!$number)
{
$error .= "<tr><td>You have not entered the verification code.</td></tr>";
}   

}

try that mate, it is wat i use

Share this post


Link to post
Share on other sites
the only problem with that code, brown2005, is that it will throw warnings whenever your form is not submitted yet. you can't refer directly to the variables without checking to see if they are set yet.

the best bet is to do something like this:
[code]
<?php
if (isset($_POST['submit'])) {
  foreach ($_POST as $key => $val) ${$key} = trim($val);
  if (empty($current_pass) || empty($new_pass) || empty($confirm_pass)) {
    echo "<div class=\"error\">The following error has occurred:</div>\n";
    if (empty($current_pass)) echo '<div class="error">You did not specify your Current Password</div>' . "\n";
    if (empty($new_pass)) echo '<div class="error">You did not specify your New password</div>' . "\n";
    if (empty($confirm_pass)) echo '<div class="error">You did not Confirm your New Password</div>' . "\n";
  }
}
?>
[/code]

hope this helps

Share this post


Link to post
Share on other sites
you got a mis-spelling in var name:

empty($confrim_pass) from the if statement,
change to $confirm from $confrim

Share this post


Link to post
Share on other sites

×

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.