session_start();
$aaa=$_REQUEST['bb'];
$_SESSION['bookrec']=array(
'book1'=>array('callno'=>123005,'price'=>number_format(1380,2),'desc'=>'Attack on Titan Anthology','auth'=>'Scott Synder'),
'book2'=>array('callno'=>123006,'price'=>number_format(844,2),'desc'=>'Binge','auth'=>'Tyler Oakley'),
'book3'=>array('callno'=>123004,'price'=>number_format(598,2),'desc'=>'A Work in Progress','auth'=>'Connor Franta'),
'book4'=>array('callno'=>123003,'price'=>number_format(668,2),'desc'=>'The Amazing Book is Not on Fire','auth'=>'Dan Howell, Phil Lester'),
'book5'=>array('callno'=>123002,'price'=>number_format(760,2),'desc'=>'Children of Eden: A Novel','auth'=>'Joey Graceffa'),
'book6'=>array('callno'=>123008,'price'=>number_format(799,2),'desc'=>'Username : Evie','auth'=>'Joe Sugg'),
'book7'=>array('callno'=>123009,'price'=>number_format(440,2),'desc'=>'The Maze Runner','auth'=>'James Dashner'),
'book8'=>array('callno'=>123007,'price'=>number_format(572,2),'desc'=>'Anne Frank: The Biography','auth'=>'Melissa Muller'),
'book9'=>array('callno'=>123001,'price'=>number_format(699,2),'desc'=>'This Book Loves You','auth'=>'Pewdiepie')
);
$selected=array();
if($aaa=='book1') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book1']);}
if($aaa=='book2') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book2']);}
if($aaa=='book3') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book3']);}
if($aaa=='book4') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book4']);}
if($aaa=='book5') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book5']);}
if($aaa=='book6') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book6']);}
if($aaa=='book7') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book7']);}
if($aaa=='book8') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book8']);}
if($aaa=='book9') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book19']);}
if($aaa=='book1') {$_SESSION['bo']=$_SESSION['bookrec']['book1']['price'];}
if($aaa=='book2') {$_SESSION['bo']=$_SESSION['bookrec']['book2']['price'];}
if($aaa=='book3') {$_SESSION['bo']=$_SESSION['bookrec']['book3']['price'];}
if($aaa=='book4') {$_SESSION['bo']=$_SESSION['bookrec']['book4']['price'];}
if($aaa=='book5') {$_SESSION['bo']=$_SESSION['bookrec']['book5']['price'];}
if($aaa=='book6') {$_SESSION['bo']=$_SESSION['bookrec']['book6']['price'];}
if($aaa=='book7') {$_SESSION['bo']=$_SESSION['bookrec']['book7']['price'];}
if($aaa=='book8') {$_SESSION['bo']=$_SESSION['bookrec']['book8']['price'];}
if($aaa=='book9') {$_SESSION['bo']=$_SESSION['bookrec']['book9']['price'];}
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book1']) {
$selected[]=$_SESSION['bo'];
echo "<table class='w3-table w3-khaki'><tr><td> ".$_SESSION['b']."</td></tr></table>";
}
}
echo "<center><b>TOTAL AMOUNT:</b> Php ".number_format(array_sum($selected),2)."</center>";
?>
我在此代码上遇到问题...当我将商品添加到购物车时,它会将商品保留在购物车中,但却出现错误
Notice: Undefined index: bb in C:\xampp\htdocs\Webcart_ch\Webcart\mycart.php on line 85
指数&#39; bb&#39;在复选框上,如果勾选了复选框,则输出内容。我真的到了那里,但我不知道该怎么办!请帮忙..
答案 0 :(得分:0)
我注意到这里有一个拼写错误的'book19': if($ aaa =='book9'){$ _SESSION ['b'] = implode(“”,$ _ SESSION ['bookrec'] [' book19 ']);}
如果这样可以解决问题,请告诉我:将'book19'更改为'book9'
if($aaa=='book9') {$_SESSION['b']=implode("<td>",$_SESSION['bookrec']['book9']);}