PHP表单回显Post变量不起作用

时间:2013-06-18 23:13:41

标签: php javascript

<?php
ob_start();
// First we execute our common code to connection to the database and start the session 
define('MyConst', TRUE);

include('../database.class.php');
include('../table.class.php'); 
include('../user.class.php');
include('../loginattempts.class.php');
include('../timer.class.php');
include('../characters.class.php');
include('../weapontype.class.php');
include('../objects/weapons/weaponobject.class.php');
include('../objects/weapons/bowieknife.class.php');
include('../npc/enemy.class.php');
include('../npc/skinhead.class.php');
include('../npc.class.php');
include('../npctype.class.php');
include('../functions.php');
include('../loginf.php');  
include('locationf.php');

$dbo = database::getInstance();
$dbo -> connect("***************", "********", "********", "***************", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); 

secSessionStart();

// At the top of the page we check to see whether the user is logged in or not 
if(empty($_SESSION['user'])) 
{ 
    // If they are not, we redirect them to the login page. 
    header("Location: login.php"); 

    // Remember that this die statement is absolutely critical.  Without it, 
    // people can view your members-only content without logging in. 
    die("Redirecting to login.php"); 
}

$_SESSION['currentlocation'] = "combat.php";
?>
<?php
if($_POST['formSubmit'] == "Submit") 
{
$varMovie = $_POST['formMovie'];

 echo $varMovie;
}
?>

<!DOCTYPE html>
<html>
<head> 
</head>
<body>


<form action="index.php" method="post">

Which is your favorite movie?
<input type="text" name="formMovie" maxlength="50">

<input type="submit" name="formSubmit" value="Submit">

</form>
</body>
</html>    

好的......所以它应该回应一些文字。相反,它只是重新加载表单!我不知道还有什么要写的,它不允许我发帖所以我只是重复我写的内容,直到达到极限。

2 个答案:

答案 0 :(得分:0)

在HTML中添加一个ELSE部分,它将显示表单或答案,但保持标题等完整。

<!DOCTYPE html>
<html>
<head> 
</head>
<body>

<?php
if($_POST['formSubmit'] == "Submit") 
{
$varMovie = $_POST['formMovie'];

 echo $varMovie;
}
else {
?>

<form action="index.php" method="post">

Which is your favorite movie?
<input type="text" name="formMovie" maxlength="50">

<input type="submit" name="formSubmit" value="Submit">

</form>
<?php } ?>
</body>
</html>    

答案 1 :(得分:0)

我倾向于使用:

<?php
if (array_key_exists("formSubmit",$_POST) && !strcmp($_POST["formSubmit"],'Submit'))
{
  $varMovie = $_POST['formMovie'];

  echo "Movie=(${varMovie})<br>\n";
}
:
:

同时注释掉上面的所有包含等,检查它是否给你formMovie的内容然后逐渐添加其他东西,直到它失败(或不)。 欢呼声。