-解決策が見つかりました--
正しいPHPコードは、user1175332とshanethehatによって以下に提供される2つの回答の組み合わせです。
正しいHTMLコード:
<?php session_start() ?>
<form method="post" action="session7.php" id="form1">
<input type="text" name="book" value="" id="book"/> Book Box
<input type="submit" value="submit" id="submit" name="submit"/>
</form>
正しいPHPコード:
<?php session_start();
if ($_POST && isset($_POST['book'])) {
$_SESSION['book'] = $_POST['book'];
}
?>
<?php
if (isset($_SESSION['book']) && $_SESSION['book'] > 0)
{echo $_SESSION['book'] . ' Book Box(es)';}
else {echo '';}
?>
これは、分離されたテスト環境で機能します。残念ながら、私が使用している実際のフォームではまだ機能しません。おそらく、JavaScriptが含まれているためです。
-----元の投稿-----
ユーザーがさまざまなアイテム(Xの1、Yの4など)の数量を入力するフォームがあります。フォームが送信されると、次のページに移動し、合計に基づいて価格が表示されます。数量/ボリューム(この部分は、StackOverflowのスタッフのおかげで機能します)。
次のページでは、記入済みのすべてのアイテム(つまり、数量が0より大きいすべてのアイテム)を表示しようとしています。たとえば、顧客がXを1つ、Yを4つ、Zが0の場合、次のページに次のように表示します。
1 X
4 Y
フォームはここで見ることができます。何らかの理由で、「未定義のインデックス」エラーが発生し続けます。
PHPコードは次のとおりです。
<?php session_start();
if ($_POST && !empty($_POST['TOTAL'])) {
$_SESSION['TOTAL'] = $_POST['TOTAL'];
}
/* this part is the first problematic part*/
if ($_POST && !empty($_POST['PROD_SP_1.5'])) {
$_SESSION['PROD_SP_1.5'] = $_POST['PROD_SP_1.5'];
}
?>
/* end of the first problematic part*/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>Untitled 1</title>
</head>
<body>
/* this part is the second problematic part*/
<?php
if ($_SESSION['PROD_SP_1.5'] > 0) {
echo $_SESSION['PROD_SP_1.5'] . 'Book Box';
}
else {
echo '';
}
?>
/* end of the second problematic part*/
<!-- This part posts the total volume in Cubic Feet-->
<?php
if (isset($_SESSION['TOTAL'])) {
echo 'Your total volume is ' . round($_SESSION['TOTAL']) . ' Cubic Feet.';
} else {
echo 'You did not fill out any details. Please go back.';
}
?>
<!-- End of volume posting -->
<br/><br/>
<!-- This part posts the correct price based on the total volume -->
<?php
if ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 250) {
echo 'The guaranteed price for door to door service is $1,899.00 based on 1 Section (up to 250CF).';
} elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 500) {
echo 'The guaranteed price for door to door service is $3,349.00 based on 2 Sections (up to 500CF).';
} elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 750) {
echo 'The guaranteed price for door to door service is $4,899.00 based on 3 Sections (up to 750CF).';
} elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 1000) {
echo 'The guaranteed price for door to door service is $5,999.00 based on an exclusive 20ft Container.';
}
elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 1250) {
echo 'The guaranteed price for door to door service is $7,499.00 based on 5 Sections (up to 1,250CF).';
}
elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 1500) {
echo 'The guaranteed price for door to door service is $8,599.00 based on 6 Sections (up to 1,500CF).';
}
elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 1750) {
echo 'The guaranteed price for door to door service is $9,499.00 based on 7 Sections (up to 1,750CF).';
}
elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 2000) {
echo 'The guaranteed price for door to door service is $9,999.00 based on an exclusive 40ft Container.';
}
else {
echo 'Sorry, your total volume is too high to quote online. Please contact us to set up an on- site survey: 1.877.430.1300';
}
?>
<!-- end of price section -->
</body>
前もって感謝します。