dimanche 18 août 2019

how to getting error in using $_get in php and send the error from another script page using header?

In my code i used $_get method to show the error in signup form.In the signup script page there are two variables m1 and m2 for email and contact error respectively.It works fine until the user put the correct values in the form,but after user enter either an incorrect email or password error it shows the error message right but along with that it shows an error as undefined index m1 is used(in case contact is incorrect) and undefined index m2 is used (in case of email is incorrect).

in the signup.php page:

<div class="form-group">
                        <input type="email" class="form-control"  placeholder="Email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"  name="e-mail" required = "true"><?php echo $_GET['m1']; ?>
                    </div>
                    <div class="form-group">
                        <input type="password" class="form-control" placeholder="Password" pattern=".{6,}" name="password" required = "true">
                    </div>
                    <div class="form-group">
                        <input type="text" class="form-control"  placeholder="Contact" maxlength="10" size="10" name="contact" required = "true"><?php echo $_GET['m2']; ?>
                    </div>

in the signup_script.php page:

if ($num != 0) {
    $m = "<span class='red'>Email Already Exists</span>";
    header('location: signup.php?m1=' . $m);
  } else if (!preg_match($regex_email, $email)) {
    $m = "<span class='red'>Not a valid Email Id</span>";
    header('location: signup.php?m1=' . $m);
  } else if (!preg_match($regex_num, $contact)) {
    $m = "<span class='red'>Not a valid phone number</span>";
    header('location: signup.php?m2=' . $m);
  } 

the error is if i put incorrect email(it shows undefined index m2 along with the Not a valid Email Id ). and if i put incorrect contact (it shows undefined index m1 along with the Not a valid phone number)




Aucun commentaire:

Enregistrer un commentaire