检查使用的表格

时间:2017-03-30 14:04:51

标签: php html forms

我通过数据库创建了待办事项列表

但登录和注册需要经过1位经理...但我不知道如何检查使用哪种表格。希望有人可以帮助我将2个PHP文件放在一个管理器中!提前感谢您的帮助!

编辑这就是它的工作原理!

经理人文件

<?php
    if ($_GET['action'] == 'login')  {
    $email = $_POST['email'];
    $wachtwoord = $_POST['pass'];
    $code       = sha1($wachtwoord);
    $pass       = crypt($code, 'ex');

    $sql = "SELECT * FROM tbl_users WHERE password = '$pass' AND email = '$email'";
    $result = $db_conn->query($sql)->rowCount();

    if ($result == 1)
    {
        session_start();
        $_SESSION['LoggedIn'] = true;
        header("Location: ../public/todo.php");
    }
    else{
        $ErrorMessage = "<strong>U heeft foutieve gegevens gebruikt, probeer het nog eens!</strong>";
        header("Location: ../public/index.php?message=$ErrorMessage");
    }
} else if($_GET['action'] == 'register')  {

    $ErrorMessage = "<strong>U moet een naam invullen!</strong>";
    if (empty($_POST['name'])){header("Location: ../public/signup.php?message=$ErrorMessage");die;}
    $ErrorMessage = "<strong>U moet een wachtwoord invullen!</strong>";
    if (empty($_POST['pass'])){header("Location: ../public/signup.php?message=$ErrorMessage");die;}
    $ErrorMessage = "<strong>U moet een geldige email invullen!</strong>";
    if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){header("Location: ../public/signup.php?message=$ErrorMessage");die;}

    $email  = $_POST['email'];

    $qry="SELECT `email` FROM `tbl_users` ORDER BY `email`";
    $qryObj = $db_conn->prepare($qry);
    $qryObj->execute();

    $resultArr = $qryObj->fetchAll(PDO::FETCH_ASSOC);

    foreach($resultArr as $row)
    {
        if ($email === $row['email']) {
            $ErrorMessage = "<strong>Deze mail bestaat al!</strong>";
            header("Location: ../public/signup.php?message=$ErrorMessage");die;
        }
    }


    $name   = htmlspecialchars($_POST['name']);
    $wachtwoord = $_POST['pass'];
    $code = sha1($wachtwoord);
    $pass = crypt($code,'ex');

    $verificatie='name='.$name.'&email='.$email.'&pass='.$pass;


    $subject = 'Verifeer uw email adres';
    $from = 'De TODO Servicedesk';
    $bericht = '/verificatie.php?'.$verificatie;

    ini_set('sendmail_from', $from);

    $headers   = array();
    $headers[] = "MIME-Version: 1.0";
    $headers[] = "Content-type: text/plain; charset=iso-8859-1";
    $headers[] = "From: TODO Servicedesk <{$from}>";
    $headers[] = "Reply-To: TODO Servicedesk <{$from}>";
    //$headers[] = "Subject: {$subject}";

    mail($email, $subject, $bericht, implode("\r\n", $headers) );
    $ErrorMessage = "<strong>Er is een activatiemail verstuurd!</strong>";
    header("Location: ../public/signup.php?message=$ErrorMessage");
}

&GT;

这是FORMS

登录表单:

<section>
<form action="../app/account_manager.php?action=login" method="POST">
    <div class="form-group">
        <label for="email">Email:</label>
        <input type="email" class="form-control" name="email">
    </div>
    <div class="form-group">
        <label for="password">Password:</label>
        <input type="password" class="form-control" name="pass">
    </div>
    <div class="form-group">
        <input type="submit" value="Login!" class="btn btn-primary" name="login">
    </div>
</form>
<?php
if (isset($_GET['message'])!= null )
{
    echo $_GET['message'];
}
?>

注册表格:

<section>
<form action="../app/account_manager.php?action=register" method="POST">
    <div class="form-group">
        <label for="name">Name:</label>
        <input type="text" class="form-control" name="name">
    </div>
    <div class="form-group">
        <label for="email">Email:</label>
        <input type="email" class="form-control" name="email">
    </div>
    <div class="form-group">
        <label for="pass">Password:</label>
        <input type="password" class="form-control" name="pass">
    </div>
    <div class="form-group">
        <input type="submit" value="Registreer!" class="btn btn-primary" name="submit">
    </div>
</form>
<?php
if (isset($_GET['message'])!= null )
{
    echo $_GET['message'];
}
?>

2 个答案:

答案 0 :(得分:0)

您可以在每个表单中使用隐藏输入。第一个和第二个表单将具有唯一的名称:form_name =“first”so

if ($_POST['form_name'] == 'first'){

}else{

}

答案 1 :(得分:0)

在您将注册表单的操作指向帐户管理器脚本后,您可以关闭提交按钮&#34; name&#34;做不同的行动。

顺便说一句,您登录表单的提交按钮目前没有名称属性。

在您的经理脚本中:

if(isset($_POST['signup'])){
    ... relevant registration code gets moved here ...
}else{
//or }elseif(isset($_POST['signin'])){  // if/when you give the button a name
    ...relevant sign in code goes here ...
}