Note that there are some explanatory texts on larger screens.

plurals
  1. POI can't get a value to stay in my $_SESSION variable
    primarykey
    data
    text
    <p>I am trying to get values out of an indexed array, but when I use a variable as the index (which is equal to an index in the array), it does not appear. I get an <code>Undefined Index</code> Error. Why is this happening? Does anyone know? Thanks!</p> <p>I have the following code:</p> <pre><code>$bookarray = array(); $books = mysqli_query($db, "SELECT * FROM books"); while($row = mysqli_fetch_assoc($books)){ $bookarray[$row['bookID']] = array( 'title' =&gt; $row['title'], 'author' =&gt; $row['author'], 'price' =&gt; $row['price'] ); } echo"&lt;hr&gt;"; print_r($bookarray); echo"&lt;hr&gt;"; echo $bookarray[5]['title']."&lt;br /&gt;"; foreach($_SESSION['cart'] as $cartedbook){ echo $cartedbook; echo $bookarray[$cartedbook]['title']; echo "&lt;br /&gt;"; } </code></pre> <p>This is the output:</p> <p><h3>Books</h3><hr></p> <pre><code>Array ( [1] =&gt; Array ( [title] =&gt; Java 2 for Pro Deelopers [author] =&gt; Michael Morgan [price] =&gt; 34.99 ) [2] =&gt; Array ( [title] =&gt; Installing XAMPP [author] =&gt; Thomas Down [price] =&gt; 24.99 ) [3] =&gt; Array ( [title] =&gt; Alice Through the Looking Glass [author] =&gt; Louis Carroll [price] =&gt; 72.35 ) [4] =&gt; Array ( [title] =&gt; Quantum Mechanics in 124 Hours [author] =&gt; Neils Bohr [price] =&gt; 24.99 ) [5] =&gt; Array ( [title] =&gt; PHP For Fun And Profit [author] =&gt; Thomas Shenk [price] =&gt; 49.99 ) [28] =&gt; Array ( [title] =&gt; Test [author] =&gt; Eric Gross [price] =&gt; 100.00 ) </code></pre> <p>) <hr>PHP For Fun And Profit<br /> 5<br /> <b>Notice</b>: Undefined index: 5 in <b>C:\xampp\htdocs\FinalProject\cart.php</b> on line <b>52</b><br /></p> <p><br /> 3<br /> <b>Notice</b>: Undefined index: 3 in <b>C:\xampp\htdocs\FinalProject\cart.php</b> on line <b>52</b><br /></p> <p>Title&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Price</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload