php函数不显示表单

时间:2013-11-19 06:46:03

标签: php session login

我在显示php功能时遇到问题。它用于管理登录表单。

功能看起来像这样 -

 function displayAdmin(){

//test if login is valid


if (isset($_SESSION['adminLogin'])){
if($_SESSION ['adminLogin']=="valid"){

    ?>

<script type="text/javascript">location.replace('addproduct.php')</script>

<?php
}

 else { 
 // test if login is invalid 
 // display error message and login form 
 if($_SESSION['adminLogin']=="invalid") { 
 echo "<div>Incorrect User ID and/or password provided</div>"; 

 ?>
<form name="adminLogin" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
                <div id="sign_up_form">
                    <label><strong>Username:</strong> <input type = "text" name="userID" class="sprited"/></label>
                    <label><strong>Password:</strong> <input type="password" name="passWord" class="sprited"/></label>
                    <div id="actions">
                    <a class="close form_button sprited" id="cancel" href="#">Cancel</a>
                    <a type ="submit" name="adminSignin"class="form_button sprited" id="log_in" href="">Sign in</a>
                    </div>
                </div>
</form>
 <?php
 } 
}

?>

<form name="adminLogin" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
                <div id="sign_up_form">
                    <label><strong>Username:</strong> <input type = "text" name="userID" class="sprited"/></label>
                    <label><strong>Password:</strong> <input type="password" name="passWord" class="sprited"/></label>
                    <div id="actions">
                    <a class="close form_button sprited" id="cancel" href="#">Cancel</a>
                    <a type ="submit" name="adminSignin"class="form_button sprited" id="log_in" href="">Sign in</a>
                    </div>
                </div>
</form>

 <?php
 } 

} // end of function

在我的页面上,我希望函数能够代码看起来像这样 -

<?php
 session_start();

 // Test that page title has been created
 if (!isset($pageTitle)) {
 $pageTitle = '<< Page title not set >>';
 }

 // include the myFunctions file
 include('includes/myFunctions.php');

 // test if login details have been keyed in
 if(!empty($_POST["userID"])) {
 // Store userID and passWord in local variables
 $userID=$_POST["userID"];
 $passWord=$_POST["passWord"];

 // check database for valid customer
 checkValidAdmin($userID, $passWord);
 }
 ?>

然后 -

<div id="sign_up">
                <h3 id="see_id">Administration Log in</h3>
            <span>Please sign in using the form below</span>
                <div><?php  displayAdmin(); ?></div>
                <a id="close_x" class="close sprited" href="#">close</a>
            </div>

我已经为这个问题进行了长时间的努力搜索,但似乎无法找到问题,如果问题突然出现在我希望收到的任何人身上!

提前非常感谢!!

3 个答案:

答案 0 :(得分:0)

$_SESSION['adminLogin']值为空,即未设置或为空。这就是内部条件不满意的原因。

答案 1 :(得分:0)

问题是你没有返回html字符串。

您应该将表单分配给变量,并在函数的末尾返回此变量。

答案 2 :(得分:0)

肯定你的$_SESSION ['adminLogin']=="valid"条件不正确。检查它是否设置正确,或者在脚本开头调用session_start();