私はいくつかのPHPコードを取得しようとしており、コードは本に従っています。しかし、このプログラムの割引を計算すると、計算はうまくいくが、名前は表示されません。これはすべてが正確に本の中でどのようになっているのかということで頭がおかしくなります...商品説明(名前)を表示させるにはどうすればよいですか?
2番目のセットこれで私を助ける目の?私はいくつかの画像と私のコードを提供します。
これは、すべてが計算された後である(「ギター」の製品説明の横に表示することになっている):
このコードはありますすべてが計算される前のHTMLテンプレート:
<!DOCTYPE html>
<html>
<head>
<title> Product Discount Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<main>
<h1>Product Discount Calculator (Complete)</h1>
<form action="display_discount.php" method="post">
<div id="data">
<label>Product Description</label>
<input type="text" name="product_description"><br>
<label>List Price</label>
<input type="text" name="list_price"><br>
<label>Discount Percent:</label>
<input type="text" name="discount_percent"><span>%</span><br>
</div>
<div id="buttons">
<label> </label>
<input type="submit" value="Calculate Discount"><br>
</form>
</main>
</body>
</html>
ポストの結果はどこにでも
フェッチされていない第二部の前の行$product_description = $_POST['product_description'];
がなければならない:全体のコードすることはできません
<?php
//get data from the form
$product_description = filter_input(INPUT_POST, 'product _description');
$list_price = filter_input(INPUT_POST, 'list_price');
$discount_percent = filter_input(INPUT_POST, 'discount_percent');
//Calculate the discount
$discount = $list_price * $discount_percent * .01;
$discount_price = $list_price - $discount;
//apply currency formatting to the dollar and percent amounts
$list_price_f = "$".number_format($list_price, 2);
$discount_percent_f = $discount_percent."%";
$discount_f = "$".number_format($discount, 2);
$discount_price_f = "$".number_format($discount_price, 2);
?>
<!DOCTYPE html>
<html>
<head>
<title> Product Discount Calculator (Complete)</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<main>
<h1> Product Discount Calculator</h1>
<label>Product Description:</label>
<span><?php echo htmlspecialchars($product_description); ?></span>
<br>
<label>List Price:</label>
<span><?php echo htmlspecialchars($list_price_f); ?></span><br>
<label>Standard Discount:</label>
<span><?php echo htmlspecialchars($discount_percent_f); ?></span><br>
<label>Discount Amount:</label>
<span><?php echo $discount_f; ?></span><br>
<label>Discount Price:</label>
<span><?php echo $discount_price_f; ?></span><br>
</main>
</body>
</html>
をあなたは変数 '$のPRODUCT_DESCRIPTIONを設定することはありません'何にでも。ユーザーがフォームを送信すると '$ _POST ['product_description']'になります。 – ceejayoz
コードが途切れていることに気付きました。申し訳ありません。全体のコードを表示できるように自分の投稿を編集しました。 – HawkBlade124