Geçersiz argüman ve tanımsız değişken foreach

0 Cevap

Ben bir form oluşturmak için çalışıyorum ve ben bu satırları bir hata alıyorum.

 else 
 {
  //report the errors.

 echo '<h1> Err ... </h1>
 <p> The following error(s) have occured</p>';

 foreach ($errors as $msg)
     {
   echo "--$msg<br />\n";
  }
  echo '</p><p>Please Try Again.</p><p><br/></p>';

 }

Peki, sorun ne? Burada hata mesajı var -

Err ...

Aşağıdaki hata (lar) oluştu var -

Notice: Undefined variable: errors in C:\wamp\www\password.php on line 107

Warning: Invalid argument supplied for foreach() in C:\wamp\www\password.php on line 107 Please Try Again.

Ben bir dizi gibi hataları belirledik.

Yukarıda benim kod -

if(isset($_POST['submitted'])) {

require_once('C:\wamp\www\connect.php');
//connecting to db

$errors = array();

if (empty($_POST['email']))

{
    $errors[]='Please enter a valid email address.';
}

İşte tam benim kod -

//forgot password update

include('C:\wamp\www\header.html');

//check if form has been submitted
require_once('C:\wamp\www\connect.php');
    //connecting to db



if(isset($_POST['submitted'])) {
    $errors = array();


    if (empty($_POST['email']))

    {
        $errors[]='Please enter a valid email address.';
    }

    else
    {
      $e = mysqli_real_escape_string($db_name,trim($_POST['email']));
    }

    //check for current password
    if (empty($_POST['password']))

    {
        $errors[]='Current password does not match.';
    }

    else
    {
      $p = mysqli_real_escape_string($db_name,trim($_POST['password']));
    }

    //check for a new password and match with confirm pass.

    if(!empty($_POST['password1']))
    {
        if($_POST['password1'] != $_POST['cpass'])
        {
            $errors[] = 'The entered password and confirm password do not match.';
        }
        else
        {
            $np=mysqli_real_escape_string($db_name,trim($_POST['password1']));
        }
    }
    if(empty($errors))
    //if everything is fine.

    //verify the entered email address and password.

    $q="SELECT username FROM users WHERE (email='$e' AND password=SHA1('$p'))";
    $r=@mysqli_query($db_name,$q);
    $num = @mysqli_num_rows($r);
    if($num==1)
    //if it matches.

    //get user id
    {
    $row=mysqli_fetch_array($r, MYSQLI_NUM);

    //udpdate query.

    $q="UPDATE users SET password= SHA1('$np') WHERE username=$row[0]";

    $r=@mysqli_query($db_name, $q);

    if (mysqli_affected_rows($db_name) ==1)

    {
        echo '<h3>Your password has been updated.</h3>';
    }

    else {
        echo '<h3>Whops! Your password cannot be changed due a system error. Try again later. Sorry</h3>';

    echo '<p>' .mysqli_error($db_name). 'Query:' . $q.'</p>';
    }


    exit();
    }
    else 
    {

        //invalid email and password

        echo 'The email address and password do not match';
    }

}
    else 
    {
        //report the errors.

    echo '<h1> Err ... </h1>
    <p> The following error(s) have occured</p>';

    foreach ($errors as $msg)
        {
            echo "--$msg<br />\n";
        }
        echo '</p><p>Please Try Again.</p><p><br/></p>';

    }


    ?>

0 Cevap