Página de inicio de sesión sin conectividad de base de datos

aquí está el código

    <body>
        <?php
          $name=$email=$pwd=$nameErr=$emailErr=$pwdErr=$flag="";

         function test_input($data)
          {
          $data = trim($data);
          $data = stripslashes($data);
          $data = htmlspecialchars($data);
          return $data;
          }

         if ($_SERVER["REQUEST_METHOD"] == "POST")
         {
         if (empty($_POST["name"]))
             { 
             $nameErr = "Name is required";
             }
          else
             {
              $name = test_input($_POST["name"]);

             if (!preg_match("/^[a-zA-Z ]*$/",$name))
              {
               $nameErr = "Only letters and white space allowed";
               $flag=0; 
               }
               else
               {
               $flag=1;
              }
            }   

           if (empty($_POST["email"]))
             {$emailErr = "Email is required";}
           else
     {
             $email = test_input($_POST["email"]);

             if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
               {
               $emailErr = "Invalid email format"; 
                   $flag=0;

                  }
               else
              {
              $flag=2;
              }
              }

     if(empty($_POST["pwd"]))
     {$pwdErr="enter password";}
      else
      {
      $pwd=test_input($_POST["pwd"]);

      if(!preg_match("/^[a-zA-Z ]*$/",$pwd))
      {
      $pwdErr="Only characters and white spaces are allowed";
      $flag=0;

      } 
      else
       {
       $flag=3;
       }
     }
     if($flag=1 && $flag=2 && $flag=3)
     {
       header("Location: login.php");
     }
     else
     {
     header("Location:form.php");
     }
 }

 ?>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">

Name:<input type="text" name="name" value="<?php echo $name; ?>"/>
<span class="error"><?php echo $nameErr; ?></span><br />

Password:<input type="password" name="pwd" value="<?php echo $pwd; ?>" />
<span class="error"><?php echo $pwdErr; ?></span><br />

Email:<input type="text" name="email" value="<?php echo $email; ?>"/>
<span class="error"><?php echo $emailErr; ?></span><br />

<input type="submit" name="submit" value="submit" />
</form>

The problem is that I want the webpage to navigate to "login.php" after validations are completed. But it is getting navigated to the "login.php" page by clicking on button and the navigations are also not getting checked.

Can anyone help me to fix this? Thanks in advance.

preguntado el 12 de febrero de 14 a las 05:02

what are you trying to accomplish? how are you 'validating' input? -

How can you assume same variable $flag has 3 different values.. if($flag=1 && $flag=2 && $flag=3) .. User different variables like $flag1, $flag2 y $flag3 to store vallues. Then if($flag1=1 && $flag2=2 && $flag3=3) -

no se puede utilizar $flag=1 in conditionals, because that always evaluates TRUE. you need to use $flag==1 for as a comparison operator. -

i want to create a simple login page, where name email and pwd is being entered. so after inserting the data, this php script should check it if all this input is correct and it should navigate to "login.php". but write now it is navigating to "login.php" without doing anything -

1 Respuestas

There is a logical problem here if($flag=1 && $flag=2 && $flag=3) and secondly you should use == for comparison. And also how $flag has a value 1,2 and 3 simultaneously? Adittionaly you should implement some session handling http://www.w3schools.com/php/php_sessions.asp http://www.php.net/manual/en/book.session.php

Respondido 12 Feb 14, 05:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.