简体   繁体   中英

php function Not Displaying form

Im having a problem displaying a php function. Its for an admin log in form.

The Function Look Like this -

 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

And on my page where I am wanting the function to sit the code looks like this -

<?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);
 }
 ?>

and then -

<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>

I have searched long and hard for this problem but can not seem to find the issue, if the issue jumps out at anyone I would love to hear from you!

Thank you so much in advance!!

$_SESSION['adminLogin'] value is empty ie not set or null. that is the reason function inside condition not satisfied.

The problem is you did'nt return the html string.

You should assign the form to a variable, and at the end of the function , return this variable.

Definitely your $_SESSION ['adminLogin']=="valid" condition is not true. Check it is set properly or session_start(); is called at beginning of the script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM