TottoBennington Posted February 19, 2012 Share Posted February 19, 2012 Notice: Undefined variable: quantity_row in C:\xampp\htdocs\cart\cart.php on line 12 Notice: Undefined index: cart_1 in C:\xampp\htdocs\cart\cart.php on line 12 Notice: Undefined index: cart_1 in C:\xampp\htdocs\cart\cart.php on line 30 Help me guys <?php session_start(); $page = 'index.php'; mysql_connect('localhost','root','')or die(mysql_error()); mysql_select_db('cart') or die(mysql_error()); if (isset ($_GET['add'])){ $quantity = mysql_query('SELECT id, quantity FROM products WHERE id ='.mysql_real_escape_string( (int)$_GET['add'])); while($quantity_rows = mysql_fetch_assoc($quantity)) { if ($quantity_row['quantity'] != $_SESSION['cart_'.$_GET['add']]) { $_SESSION['cart_'.$_GET['add']] += '1'; } } } function products() { $get = mysql_query('SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER BY id DESC') or die(mysql_error()); if (mysql_num_rows($get) == 0) { echo 'There are no products to display!'; } else { while ($get_row = mysql_fetch_assoc($get)) { echo '<p>'.$get_row['name']. '<br />' .$get_row['description']. '<br />'.number_format( $get_row['price'], 2) . '<a href="cart.php?add='. $get_row['id'].'">Add</a></p>'; } } } echo $_SESSION['cart_1']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/257327-undefined-variable/ Share on other sites More sharing options...
smerny Posted February 19, 2012 Share Posted February 19, 2012 while($quantity_rows = mysql_fetch_assoc($quantity)) { if ($quantity_row['quantity'] != $_SESSION['cart_'.$_GET['add']]) you initiate quantity_rows and then check quantity_row (no "s") Quote Link to comment https://forums.phpfreaks.com/topic/257327-undefined-variable/#findComment-1319007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.