<html>
<head>
<title>Newspaper</title>
</head>
<body>
<h1>How much does it cost</h1>
<p>This form will allow you to find out how much a newspaper costs</p>
<form name="choose" action="response.php" method="POST">
<p>Which newspaper are you interested in?
<?php
$newspaper = array("The Guardian", "The Times", "The Sun", "The Mirror");
echo '<select name="newspaper">';
for ($i = 0; $i < count($newspaper); $i++) {
echo '<option value="' . $i . '">' ;
echo $newspaper[$i] ;
echo '</option>';
}
echo '</select>';
?>
</p>
<p>Press to get the price<input type="submit" name="continue" value="continue" /></p>
</form>
</body>
</html>
<?php
$newspaper=$_POST['newspaper'];
$newspaperNames= array ("The Guardian", "The Times", "The Sun", "The Mirror");
$newspaperPrice= array('0.9','1','0.5','0.5');
?>
<html>
<head>
<title>Newspaper</title>
</head>
<body>
<h1>How much does it cost</h1>
<?php
print "<p> Your Newspaper is " .$newspaper. "</p>";
print "<p>Your Newspaper is " .$newspaper. "</p>";
if ($newspaper== "The Guardian") {
print "<p>Your newspaper cost " .$newspaperPrice[0]."</p>";
} else
?>
</body>
</html>
你好樣的一個小白用PHP。有一個問題,出於某種原因,我無法讓選定的數組繼續到響應頁面,它將顯示從前一個數組中選擇的內容,並且如果選擇了該報紙,第二個數組中的正確價格將出現?
爲了調試,你可以使用的print_r ($ _POST) – Phil
正確。我認爲最好使用多維數組而不是兩個數組。但這更多取決於這個腳本將被使用的方式以及代碼創建者的「樣式」。 –