2014-12-04 31 views
0

我在試圖讓這個例子工作時遇到了問題。我有一個相對簡單的HTML和PHP文件,但是當我提交它時,它不會顯示另一頁上的PHP文件中的內容。有什麼我失蹤?由於試圖讓HTML和PHP能夠正常工作

這裏的HTML:

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<!-- This is assign11.html --> 
<html> 
<head> 
    <title>Process the HTML form data with the POST method</title> 
</head> 
<body> 
    <form name="myform" action="assign11.php" method="POST"> 
    <input type="hidden" name="check_submit" value="1" /> 
    Name: <input type="text" name="Name" /><br /> 
    Password: <input type="password" name="Password" maxlength="10" /><br /> 
    Select something from the list: <select name="Seasons"> 
     <option value="Spring" selected="selected">Spring</option> 
     <option value="Summer">Summer</option> 
     <option value="Autumn">Autumn</option> 
     <option value="Winter">Winter</option> 
    </select><br /><br /> 
    Choose one: 
     <input type="radio" name="Country" value="USA" /> USA 
     <input type="radio" name="Country" value="Canada" /> Canada 
     <input type="radio" name="Country" value="Other" /> Other 
    <br /> 
Choose the colors: 
    <input type="checkbox" name="Colors[]" value="green" checked="checked" /> Green 
    <input type="checkbox" name="Colors[]" value="yellow" /> Yellow 
    <input type="checkbox" name="Colors[]" value="red" /> Red 
    <input type="checkbox" name="Colors[]" value="gray" /> Gray 
<br /><br /> 
Comments:<br /> 
<textarea name="Comments" rows="10" cols="60">Enter your comments here</textarea><br /> 
<input type="submit" /> 
</form> 
</body> 
</head> 
</html> 

而這裏的PHP:

<?php 
//Check whether the form has been submitted 
if (array_key_exists('check_submit', $_POST)) { 
    //Converts the new line characters (\n) in the text area into HTML line breaks (the <br /> tag) 
    $_POST['Comments'] = nl2br($_POST['Comments']); 
    //Check whether a $_GET['Languages'] is set 
    if (isset($_POST['Colors'])) { 
    $_POST['Colors'] = implode(', ', $_POST['Colors']); //Converts an array into a single string 
    } 

//Let's now print out the received values in the browser 
echo "Your name: {$_POST['Name']}<br />"; 
echo "Your password: {$_POST['Password']}<br />"; 
echo "Your favourite season: {$_POST['Seasons']}<br /><br />"; 
echo "Your comments:<br />{$_POST['Comments']}<br /><br />"; 
echo "You are from: {$_POST['Country']}<br />"; 
echo "Colors you chose: {$_POST['Colors']}<br />"; 
} else { 
    echo "You can't see this page without submitting the form."; 
} 
?> 
+0

也分享當前輸出。 – amit 2014-12-04 05:44:03

回答

1

取而代之的這條線

if (array_key_exists('check_submit', $_POST)) 

使用:

if(isset($_POST)) 
+0

這不是我的本地機器上的工作,但它與我的老師網站在線工作。所以它在那裏工作對我有用:)感謝您的建議! – 2014-12-04 05:47:21

+0

還有一個問題:如果我想創建另一個顯示「購買確認」或類似的東西的PHP文件,我該怎麼做?我可以在php文件中加入「確認」按鈕嗎? – 2014-12-04 05:52:06

+0

對不起,但我並沒有明白你的意見。你可以重定向到另一個PHP文件,如果你想要哪些可能顯示購買確認.. – 2014-12-04 06:12:19