提交按钮没有作出反应

时间:2016-07-25 07:59:18

标签: php

我正在使用登录表单测试连接。在提交过程中没有错误。我认为提交按钮没有反应,但我不知道为什么。可能是什么问题?

这是有问题的代码:

<?php 
  session_start();
  require_once '../functions.php';
  $errors = array();

  if (isset($_POST['email']) && isset($_POST['password'])) {
    $email = addslashes(htmlspecialchars(htmlentities(trim($_POST['email']))));
    $password = sha1($_POST['password']);

    require '../dbconnection.php';

    $req = $pdo->prepare('SELECT * FROM utilisateurs WHERE password =  "'.$password.'" AND  email =  "'.$email.'" ');
    $count = $req->rowCount();
    if ($count == 1) {
      $_SESSION['id'] = $req->fetch();
      header('Location: ../index.php');

    }else{
      $message = "Nom d'utilisateur ou mot de passe incorrecte ";
    }

  }else{
    echo "<div class=\"alert alert-danger\">
      <p>Vous devez remplir tous les champs !<p>
    </div>";
  }
?>

更新

这是提交代码

<form action="" method="post">
    <div class="form-group has-feedback">
        <input type="email" name = "email" class="form-control" placeholder="Email">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
    </div>
    <div class="form-group has-feedback">
        <input type="password" name = "password" class="form-control" placeholder="Mot de passe">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
    </div>
    <div class="row">
        <div class="col-xs-8">
            <div class="checkbox icheck">
                <label>
                    <input style = "color: white;" type="checkbox"> Se souvenir de moi
                </label>
            </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
            <button type="submit" class="btn btn-bg btn-block btn-purple">Connexion</button>
        </div>
        <!-- /.col -->
    </div>
</form>

2 个答案:

答案 0 :(得分:2)

表单action属性为空,在这里提供一个php文件名,如something.php

答案 1 :(得分:0)

将此代码放入文件(例如:check.php)

    <?php 
  session_start();
  require_once '../functions.php';
  $errors = array();

  if (isset($_POST['email']) && isset($_POST['password'])) {
    $email = addslashes(htmlspecialchars(htmlentities(trim($_POST['email']))));
    $password = sha1($_POST['password']);

    require '../dbconnection.php';

    $req = $pdo->prepare('SELECT * FROM utilisateurs WHERE password =  "'.$password.'" AND  email =  "'.$email.'" ');
    $count = $req->rowCount();
    if ($count == 1) {
      $_SESSION['id'] = $req->fetch();
      header('Location: ../index.php');

    }else{
      $message = "Nom d'utilisateur ou mot de passe incorrecte ";
    }

  }else{
    echo "<div class=\"alert alert-danger\">
      <p>Vous devez remplir tous les champs !<p>
    </div>";
  }
?>

将此代码放入文件(例如:index.html)

 <form action="check.php" method="post">
  <div class="form-group has-feedback">
    <input type="email" name = "email" class="form-control" placeholder="Email">
    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
  </div>
  <div class="form-group has-feedback">
    <input type="password" name = "password" class="form-control" placeholder="Mot de passe">
    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
  </div>
  <div class="row">
    <div class="col-xs-8">
      <div class="checkbox icheck">
        <label>
          <input style = "color: white;" type="checkbox"> Se souvenir de moi
        </label>
      </div>
    </div>
    <!-- /.col -->
    <div class="col-xs-4">
      <button type="submit" class="btn btn-bg btn-block btn-purple">Connexion</button>
    </div>
    <!-- /.col -->
  </div>
</form>

在您的浏览器中访问index.html这将100%