2013-02-28 2 views
-1

"제출"버튼을 클릭하면 두 개의 echo 문으로 HTML 페이지를 덮어 쓸 것으로 예상됩니다. 그러나 덮어 쓰기는 발생하지 않습니다. 페이지가 Apache에 연결되었습니다. 내가 제대로 이해하면

<?php 
$username = $_POST['username']; 
$password = $_POST['password']; 

if (!isset($_POST['submit'])) 
{ 
    // if page is not submitted to itself echo the form 
} 
else { 
    echo("Hello, " . $_POST['username']); 
    echo("Your password is " . $_POST['password'] . "!"); 
} 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>Visual Debate Home</title> 
</head> 
<body> 
    <h1>Visual Debate</h1> 
    <form method="post" action="?"> 
     <div>Username: </div><div><input type="text" name="username" size="20" maxlength="20"></div> 
     <div>Password: </div><input type="password" name="password" size="15" maxlength="15"></div> 
     <div><input type="submit" value="submit" name="submit"></div> 
    </form> 

</body> 
</html> 
+0

게시 한 코드에 HTML과 폼이 무조건적으로 출력됩니다. 양식이 제출되면 인쇄 한 메시지가 HTML 코드 위에 표시됩니다. – drew010

답변

2

, 당신이 추구하고 있습니다 :

<?php 
$username = $_POST['username']; 
$password = $_POST['password']; 

if (!isset($_POST['submit'])) 
{ 
    // if page is not submitted to itself echo the form 
} 
else { 
    echo("Hello, " . $_POST['username']); 
    echo("Your password is " . $_POST['password'] . "!"); 
    die(); // stops the script execution! note that you can use die("like this") to output the "like this" and stop the script execution there. 
} 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>Visual Debate Home</title> 
</head> 
<body> 
    <h1>Visual Debate</h1> 
    <form method="post" action="?"> 
     <div>Username: </div><div><input type="text" name="username" size="20" maxlength="20"></div> 
     <div>Password: </div><input type="password" name="password" size="15" maxlength="15"></div> 
     <div><input type="submit" value="submit" name="submit"></div> 
    </form> 

</body> 
</html> 
+0

이 정확한 코드를 실행 해 보았습니다. 결과가 없습니다. 나는 이것이 IDE 문제라고 생각하고있다. 다들 감사 해요. –

+1

IDE가 문제를 나타내지 않아야합니다. –

1

페이지의 HTML하는 것은 항상 표시됩니다 의미, 당신의 PHP의 ifelse 논리를 벗어납니다. 나는 개인적으로 다음과 같이 할 것입니다 :

<?php 
    $username = $_POST['username']; 
    $password = $_POST['password']; 

    if (isset($_POST['submit'])): 
     // Form was submitted to itself -- overwrite the form 
     echo("Hello, " . $_POST['username']); 
     echo("Your password is " . $_POST['password'] . "!"); 
    else: 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>Visual Debate Home</title> 
</head> 
<body> 
    <h1>Visual Debate</h1> 
    <form method="post" action="?"> 
     <div>Username: </div><div><input type="text" name="username" size="20" maxlength="20"></div> 
     <div>Password: </div><input type="password" name="password" size="15" maxlength="15"></div> 
     <div><input type="submit" value="submit" name="submit"></div> 
    </form> 

</body> 
</html> 
<?php endif; ?> 
+0

원래 코드를 준비했지만 원래 동일한 문제가있었습니다. 정확한 코드를 실행하고 있지만 결과는 아직 없습니다. –

+1

그래, [PhpFiddle] (http://phpfiddle.org/)에서 내 코드 (또는 즐 라탄)를 실행하면 두 가지 접근법 모두 작동한다는 것을 알 수 있습니다. 서버/PHP 구성에 문제가 있습니다. – Liv