2017-05-01 15 views
-2

現在、セッションを使用してコードをアップグレードするのに苦労しています。ケースはウェブカートに関するものです。私は今、カートに入れるプロセスに入っています。セッションを使用して、ユーザーが選択したアイテムを保持したいと考えています。しかし、私はこのセッションを使用するたびに、この行動の発生はないようです。この問題について私を助けてください。 btw、これがコードです。多次元配列でセッションが動作しない

<?php session_start(); 
     $q1=isset($_REQUEST['attack']) ? $_REQUEST['attack'] : 'no_value'; 
     if(is_numeric($q1)){ $q1=number_format($q1,0);} 
     $q2=isset($_REQUEST['binge']) ? $_REQUEST['binge'] : 'no_value'; 
     if(is_numeric($q2)){ $q2=number_format($q2,0);} 
     $q3=isset($_REQUEST['con']) ? $_REQUEST['con'] : 'no_value'; 
     if(is_numeric($q3)){ $q1=number_format($q3,0);} 
     $q4=isset($_REQUEST['dan_ph']) ? $_REQUEST['dan_ph'] : 'no_value'; 
     if(is_numeric($q4)){ $q1=number_format($q4,0);} 
     $q5=isset($_REQUEST['childeden']) ? $_REQUEST['childeden'] : 'no_value'; 
     if(is_numeric($q5)){ $q1=number_format($q5,0);} 
     $q6=isset($_REQUEST['userevie']) ? $_REQUEST['userevie'] : 'no_value'; 
     if(is_numeric($q6)){ $q1=number_format($q6,0);} 
     $q7=isset($_REQUEST['maze']) ? $_REQUEST['maze'] : 'no_value'; 
     if(is_numeric($q7)){ $q1=number_format($q7,0);} 
     $q8=isset($_REQUEST['annefrank']) ? $_REQUEST['annefrank'] : 'no_value'; 
     if(is_numeric($q8)){ $q1=number_format($q8,0);} 
     $q9=isset($_REQUEST['pewds']) ? $_REQUEST['pewds'] : 'no_value'; 
     if(is_numeric($q9)){ $q1=number_format($q9,0);} 

     $_SESSION['bookrec']=array(
     'book1'=>array('callno'=>123005,'price'=>1380,'desc'=>'Attack on Titan Anthology','auth'=>'Scott Synder','quant'=>(int)$q1,'total'=>1380*(int)$q1), 
     'book2'=>array('callno'=>123006,'price'=>number_format(844,2),'desc'=>'Binge','auth'=>'Tyler Oakley','quant'=>(int)$q2,'total'=>number_format(844,2)*(int)$q2), 
     'book3'=>array('callno'=>123004,'price'=>number_format(598,2),'desc'=>'A Work in Progress','auth'=>'Connor Franta','quant'=>(int)$q3,'total'=>number_format(598,2)*(int)$q3), 
     'book4'=>array('callno'=>123003,'price'=>number_format(668,2),'desc'=>'The Amazing Book is Not on Fire','auth'=>'Dan Howell, Phil Lester','quant'=>(int)$q4,'total'=>number_format(668,2)*(int)$q4), 
     'book5'=>array('callno'=>123002,'price'=>number_format(760,2),'desc'=>'Children of Eden: A Novel','auth'=>'Joey Graceffa','quant'=>(int)$q5,'total'=>number_format(760,2)*(int)$q5), 
     'book6'=>array('callno'=>123008,'price'=>number_format(799,2),'desc'=>'Username : Evie','auth'=>'Joe Sugg','quant'=>(int)$q6,'total'=>number_format(799,2)*(int)$q6), 
     'book7'=>array('callno'=>123009,'price'=>number_format(440,2),'desc'=>'The Maze Runner','auth'=>'James Dashner','quant'=>(int)$q7,'total'=>number_format(440,2)*(int)$q7), 
     'book8'=>array('callno'=>123007,'price'=>number_format(572,2),'desc'=>'Anne Frank: The Biography','auth'=>'Melissa Muller','quant'=>(int)$q8,'total'=>number_format(572,2)*(int)$q8), 
     'book9'=>array('callno'=>123001,'price'=>number_format(699,2),'desc'=>'This Book Loves You','auth'=>'Pewdiepie','quant'=>(int)$q9,'total'=>number_format(699,2)*(int)$q9) 
     ); 
     $SESSION['selected']=array(); 
     $selected=$SESSION['selected']; 

     $b1=implode("<td>",(array)$_SESSION['bookrec']['book1']); 
     $b2=implode("<td>",(array)$_SESSION['bookrec']['book2']); 
     $b3=implode("<td>",(array)$_SESSION['bookrec']['book3']); 
     $b4=implode("<td>",(array)$_SESSION['bookrec']['book4']); 
     $b5=implode("<td>",(array)$_SESSION['bookrec']['book5']); 
     $b6=implode("<td>",(array)$_SESSION['bookrec']['book6']); 
     $b7=implode("<td>",(array)$_SESSION['bookrec']['book7']); 
     $b8=implode("<td>",(array)$_SESSION['bookrec']['book8']); 
     $b9=implode("<td>",(array)$_SESSION['bookrec']['book9']); 

     $bo1=$_SESSION['bookrec']['book1']['total']; 
     $bo2=$_SESSION['bookrec']['book2']['total']; 
     $bo3=$_SESSION['bookrec']['book3']['total']; 
     $bo4=$_SESSION['bookrec']['book4']['total']; 
     $bo5=$_SESSION['bookrec']['book5']['total']; 
     $bo6=$_SESSION['bookrec']['book6']['total']; 
     $bo7=$_SESSION['bookrec']['book7']['total']; 
     $bo8=$_SESSION['bookrec']['book8']['total']; 
     $bo9=$_SESSION['bookrec']['book9']['total']; 


       If(isset($_POST['book1'])){ 
        foreach($_SESSION['bookrec'] as $data){ 
         if($data == $_SESSION['bookrec']['book1']){ 
          $selected=$bo1; 
          $SESSION['selected']=$selected; 
          echo "<table class='w3-table w3-khaki'><tr><td>&nbsp".$b1."</td></tr></table>"; 
         } 
        } 
       } 
       If(isset($_POST['book2'])){ 
        foreach($_SESSION['bookrec'] as $data){ 
         if($data == $_SESSION['bookrec']['book2']){ 
          $selected[]=$bo2; 
          echo "<table class='w3-table w3-khaki'><tr><td>&nbsp".$b2."</td></tr></table>"; 
         } 
        } 
       } 
       If(isset($_POST['book3'])){ 
        foreach($_SESSION['bookrec'] as $data){ 
         if($data == $_SESSION['bookrec']['book3']){ 
          $selected[]=$bo3; 
          echo "<table class='w3-table w3-khaki'><tr><td>&nbsp".$b3."</td></tr></table>"; 
         } 
        } 
       } 
       If(isset($_POST['book4'])){ 
        foreach($_SESSION['bookrec'] as $data){ 
         if($data == $_SESSION['bookrec']['book4']){ 
          $selected[]=$bo4; 
          echo "<table class='w3-table w3-khaki'><tr><td>&nbsp".$b4."</td></tr></table>"; 
         } 
        } 
       } 
       If(isset($_POST['book5'])){ 
        foreach($_SESSION['bookrec'] as $data){ 
         if($data == $_SESSION['bookrec']['book5']){ 
          $selected[]=$bo5; 
          echo "<table class='w3-table w3-khaki'><tr><td>&nbsp".$b5."</td></tr></table>"; 
         } 
        } 
       } 
       If(isset($_POST['book6'])){ 
        foreach($_SESSION['bookrec'] as $data){ 
         if($data == $_SESSION['bookrec']['book6']){ 
          $selected[]=$bo6; 
          echo "<table class='w3-table w3-khaki'><tr><td>&nbsp".$b6."</td></tr></table>"; 
         } 
        } 
       } 
       If(isset($_POST['book7'])){ 
        foreach($_SESSION['bookrec'] as $data){ 
         if($data == $_SESSION['bookrec']['book7']){ 
          $selected[]=$bo7; 
          echo "<table class='w3-table w3-khaki'><tr><td>&nbsp".$b7."</td></tr></table>"; 
         } 
        } 
       } 
       If(isset($_POST['book8'])){ 
        foreach($_SESSION['bookrec'] as $data){ 
         if($data == $_SESSION['bookrec']['book8']){ 
          $selected[]=$bo8; 
          echo "<table class='w3-table w3-khaki'><tr><td>&nbsp".$b8."</td></tr></table>"; 
         } 
        } 
       } 
       If(isset($_POST['book9'])){ 
        foreach($_SESSION['bookrec'] as $data){ 
         if($data == $_SESSION['bookrec']['book9']){ 
          $selected[]=$bo9; 
          echo "<table class='w3-table w3-khaki'><tr><td>&nbsp".$b9."</td></tr></table>"; 
         } 
        } 
       } 
       If(empty(isset($_POST['book1'])) && empty(isset($_POST['book2'])) && empty(isset($_POST['book3'])) && empty(isset($_POST['book4'])) && empty(isset($_POST['book5'])) && empty(isset($_POST['book6'])) && empty(isset($_POST['book7'])) && empty(isset($_POST['book8'])) && empty(isset($_POST['book9']))){ 
        echo "<table class='w3-table w3-khaki'><tr><td>No items yet<td></tr></table>"; 
       } 

       echo "<center><b>TOTAL AMOUNT:</b> Php ".number_format(array_sum((array)$selected),2)."</center>"; 

       ?> 
+0

無関係なコードを減らす必要があります。 –

+0

マティア恐竜----好きですか?これについての研究を行っていますが、役に立たないと思われます。 –

+0

コードが多すぎる場合は、減らしてください。それぞれの行を読みたくありません。 –

答えて

0

サーバーが、ルータに接続されている場合は、同じページ

2)についても同様の要求にセッション値を取得することはできません)という

1のためresonsをfoll0wingがあるかもしれませんあなたdbベースのセッションを使用する必要があります。