jmclocals Posted July 13, 2010 Share Posted July 13, 2010 Hey, Im having a problem extracting a specific ID from a MySQL database and displaying it in the form I've built. The form just appears blank/non-existent. I'm getting a Fatal error (line 27) in my 'functions.inc.php' file. Can someone please help me out. Thanks Heres my script: <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM deals WHERE id = '.$id; $array = array('id', 'title', 'price', 'qty'); extract($array); } $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$title.' by '.$author.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/207637-error-extracting-info-from-database-into-web-form-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 13, 2010 Share Posted July 13, 2010 The posted code by itself does not produce any error. Perhaps if you post the exact error message and the context where the code is being used that does produce the error. Quote Link to comment https://forums.phpfreaks.com/topic/207637-error-extracting-info-from-database-into-web-form-help/#findComment-1085470 Share on other sites More sharing options...
jmclocals Posted July 13, 2010 Author Share Posted July 13, 2010 Hey, Thanks for getting back to me so quickly. Here are the errors I'm getting: Warning: join() [function.join]: Invalid arguments passed in /home/content/36/6079136/html/cart/inc/functions.inc.php on line 44 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/36/6079136/html/cart/inc/functions.inc.php:44) in /home/content/36/6079136/html/cart/cart.php on line 9 Ive also included my 'cart' for you to see considering I'm now getting an error there as well. Thanks in advance! <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Your Daily Deal</title> <link rel="stylesheet" type="text/css" href="../CSS/e_stylesheet.css"/> <script src="../Scripts/swfobject_modified.js" type="text/javascript"></script> </head> <body> <div id="shoppingcart_wrapper"> <div id="logo_cart"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="455" height="300" id="FlashID" title="Welcome to AnotherDailyDeal!"> <param name="movie" value="../flash/logo_intro_final.swf" /> <param name="quality" value="high" /> <param name="wmode" value="transparent" /> <param name="swfversion" value="6.0.65.0" /> <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. --> <param name="expressinstall" value="../Scripts/expressInstall.swf" /> <param name="LOOP" value="false" /> <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. --> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="../flash/logo_intro_final.swf" width="455" height="300"> <!--<![endif]--> <param name="quality" value="high" /> <param name="wmode" value="transparent" /> <param name="swfversion" value="6.0.65.0" /> <param name="expressinstall" value="../Scripts/expressInstall.swf" /> <param name="LOOP" value="false" /> <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. --> <div> <h4>Content on this page requires a newer version of Adobe Flash Player.</h4> <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p> </div> <!--[if !IE]>--> </object> <!--<![endif]--> </object> </div> <div id="shoppingcart_content_wrap"> <div id="shoppingcart_content"> <h1>Your Shopping Cart</h1> <div id="cart_purchaseDetails_echo"> <?php echo writeShoppingCart(); ?> </div> <h2>Please review details.</h2> <div id="cart_purchaseDetails_echo2"> <?php echo showCart(); ?> </div> <p class="coupon_back_link"><a href="../user/ind_memlog.php">Back to coupon</a></p> </div> </div><!--close_contentWrap--> </div><!--close_wrapper--> <script type="text/javascript"> <!-- swfobject.registerObject("FlashID"); //--> </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/207637-error-extracting-info-from-database-into-web-form-help/#findComment-1085473 Share on other sites More sharing options...
PFMaBiSmAd Posted July 13, 2010 Share Posted July 13, 2010 The edited code in your first post is not the same as originally posted and now produces a fatal parse error. It is extremely difficult to help with code that is a moving target. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/207637-error-extracting-info-from-database-into-web-form-help/#findComment-1085481 Share on other sites More sharing options...
jmclocals Posted July 13, 2010 Author Share Posted July 13, 2010 Sorry about that... I shouldn't have changed my script in the slightest until I heard back from you... My script is back to the state it was in when I posted the thread, and this is my error: Parse error: syntax error, unexpected T_ELSE in /home/content/36/6079136/html/cart/inc/functions.inc.php on line 43 Quote Link to comment https://forums.phpfreaks.com/topic/207637-error-extracting-info-from-database-into-web-form-help/#findComment-1085483 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.