オーダーする個数を決めてsubmitを押すとNotice: Undefined index: Santa MonicaとNotice: Undefined index: Bevery Hillsと表示され、HollyWoodとDowntownは正常に表示されます。arrayで4つの地名をまとめてforeachでそれぞれ表示しているのですが、Santa MonicaとBevery Hillsのエラーがでる原因がわからないので、教えていただきたいです。
class La { public $name; //プロパティ public $image; public $price; private $orderCount = 0; public function __construct($name, $image, $price){ $this->name = $name; $this->image = $image; $this->price = $price; } public function getName(){ return $this->name; } public function getTaxIncludedPrice(){ return $this->price * 1.08; } public function getOrderCount(){ return $this->orderCount; } public function setOrderCount($orderCount){//プロパティの値を変更するメソッド $this->orderCount = $orderCount; } public function getTotalPrice(){ return $this->getTaxIncludedPrice() * $this->orderCount; } } *************** *****オーダーの個数を記入するページです******* <!DOCTYPE html> <html> <head> <title>Los Angeles</title> <link rel="stylesheet" type="text/css" href="samplephp.css"> </head> <body> <div class= "wrapper container"> <div class="header"> <strong>Los Angeles</strong> </div> <h1 class="logo">Los Angeles</h1> <div>Today:<?php //echo data('Y m d');?></div> <!-- 価格(税込)と人数と注文時に価格を合計する--> <form action="confirm.php" method="post"> <div class="menu-items"> <?php foreach($cities as $city) : ?> <div class= "menu-item"> <h3><?php echo $city->name; ?></h3> <img src="<?php echo $city->image; ?>"> <p>???? <?php echo $city->price; ?></p> <p>Included Tax: $<?php echo $city->getTaxIncludedPrice(); ?></p> <input type="text" value="0" name="<?php echo $city->getName();?>"> </div> <?php endforeach ?> </div> <input type="submit" value="SUBMIT"> </form> </div> </body> </html> *********** ****オーダー結果を表示するページです*******! <?php require_once('samplephpdata.php'); ?> <!DOCTYPE html> <html> <head> <title>Order Confirmation</title> <link rel="stylesheet" type="text/css" href="samplephp.css"> </head> <body> <div class= "wrapper container"> <div class="header"> <strong>Los Angeles</strong> </div> <h1 class="logo">Order Confirmation</h1> <div class="menu-items"> <?php foreach($cities as $city) : ?> <div class= "menu-item"> <?php $orderCount = $_POST[$city->getName()];?> <?php $city->setOrderCount($orderCount); ?> <p> <?php echo $city->getName() ?> : <?php echo $orderCount; ?> 人 </p> <p>Total cost:$<?php echo $city->getTotalPrice() ?></p> </div> <?php endforeach ?> </div> </div> </body> </html> ************* <?php require_once("samplephpmenu.php"); $santamonica = new La("Santa Monica","IMG_0533.jpg",40); $beveryhills = new La("Bevery Hills",'IMG_0194.jpg',35); $hollywood = new La("HollyWood",'IMG_1603.jpg',20); $donwtown = new La("Donwtown",'IMG_0635.jpg',10); $cities = [$santamonica, $beveryhills, $hollywood, $donwtown]; ?>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/30 07:47
2017/10/30 08:06
2017/10/30 10:26
2017/10/31 01:49
2017/10/31 04:30
2017/10/31 04:40