点击提交后无法输出数据

时间:2013-06-25 15:26:12

标签: php

我有3个php文件: 1st login-form.php

<?php
if(isset($_POST['user']) && isset($_POST['password']))
{
    if(!empty($_POST['user']) && !empty($_POST['password']))
    {
    $user=$_POST['user'];
    $password=$_POST['password'];
    header('location:index-test.php');
    }
}
?>
<form action='index-test.php' method='post'>
Username <input type='text' name='user'/><br>
Password <input type='text' name='password'/><br>
<input type='submit' name='submit' value='submit'/>
</form>

2nd index-test.php

 <?php
require 'core-test.php';

if(loggedin())
{
echo 'ok';
}
else
{
include 'login-form.php';
}


?>

3rd core-test.php

<?php
function loggedin()
{
    if(isset($user) && isset($password))
    {
    return true;
    }
    else
    {
    return false;
    }
}
?>

当我键入index.php.It将输出login-from.php,因为我还没有输入数据。但是当我输入数据并单击提交时,它仍然显示登录表单而不是消息“确定”。我哪里错了?

2 个答案:

答案 0 :(得分:0)

在core-test.php中,您需要$_POST['user']而不是$user;同样是为了密码。

答案 1 :(得分:0)

我认为您的意思是将login-form.php中的表单发布到login-form.php本身。如果您已完成将其发布到index-test.php,那么就不会设置$user$password

您可以按照其他人提供的步骤操作,或者只更改表单的action=属性,并保留现有代码。

您唯一需要做的就是更改此行

<form action='index-test.php' method='post'>

到这个

<form action='login-form.php' method='post'>

和宾果!

希望这会有所帮助。