0

提交表单后,我想在用户类中调用我的函数,到目前为止,我有以下内容:

if(isset($_POST)){
$run = new Users();}
$run->preventaccess();

if(isset($_POST['registerForm'])) {
$run->validate();
$run->insert();
}


if(isset($_POST['loginForm'])) {
$run->login($username, $password);
$run->validatelogin();}

然而这根本不起作用,它把我带到我的课程页面,但页面留空并且查询没有执行?

有什么想法可以让它发挥作用吗?

<form id="loginForm" name="loginForm" method="POST" action="classes/class.Users.php">
        <h1><span class="log-in">Log in</span> or <span class="sign-up"><a href="register">sign up</a></span></h1>
        <div id="errorDiv"></div>
    <p class="float">
        <label for="login"><i class="icon-user"></i>Username</label>
        <input type="text" id="username" name="username" placeholder="Username">
          <span class="errorFeedback errorSpan" id="emailError">Username is required</span>
    </p>
    <p class="float">
        <label for="password"><i class="icon-lock"></i>Password</label>
        <input type="password" id="password" name="password" placeholder="Password" class="showpassword"> 
                <span class="errorFeedback errorSpan" id="passwordError">Password is required</span>

    </p>
    <p class="clearfix"> 
        <input type="submit" name="submit" value="Log in"></form>
    </p>   
4

2 回答 2

0

尝试在文档中包含函数脚本??!

<?php include_once("../path/to/functions.php"); ?>

HTML goes here?

我在这里错过了一些非常明显的东西吗?您必须以某种方式使您的功能可用于页面。

于 2013-09-12T15:56:59.630 回答
0

试试这个

    if(isset($_POST)){
$run = new Users();}
$run->preventaccess();

if(isset($_POST['registerForm'])) {
$run->validate();
$run->insert();
}


if(isset($_POST['usethisvalue'])) {
$run->login($username, $password);
$run->validatelogin();}

<form id="loginForm" name="loginForm" method="POST" action="classes/class.Users.php">
        <h1><span class="log-in">Log in</span> or <span class="sign-up"><a href="register">sign up</a></span></h1>
        <div id="errorDiv"></div>
    <p class="float">
        <label for="login"><i class="icon-user"></i>Username</label>
        <input type="text" id="username" name="username" placeholder="Username">
          <span class="errorFeedback errorSpan" id="emailError">Username is required</span>
    </p>
    <p class="float">
        <label for="password"><i class="icon-lock"></i>Password</label>
        <input type="password" id="password" name="password" placeholder="Password" class="showpassword"> 
                <span class="errorFeedback errorSpan" id="passwordError">Password is required</span>

    </p>
    <p class="clearfix"> 
        <input type="submit" name="usethisvalue" value="Log in"></form>
    </p>   

您不应该在您的发布方法中使用表单名称,而是在您的提交中指定名称,如图所示并在您的发布方法中检查它。

于 2013-09-12T17:35:11.697 回答