riddhi Posted April 18, 2007 Share Posted April 18, 2007 I have created the budget.php which is as follows:- <? require_once 'library/config.php'; require_once 'library/cart-functions.php'; if (!defined('WEB_ROOT')) { exit; } ?> [b]// A Dynamic list created with a form for the provision for input [/b] <? extract($_POST); // Extracts POST Gobal Array extract($_GET); global $total,$price,$pos; if(isset($submit)){ [b]// Checks errors After submission by calling a function [/b] if(ereg("[0-9]",$category)){ // Checks Numeric Entry by user $res=dbQuery("SELECT B.PD_THUMBNAIL,B.PD_NAME, B.PD_DESCRIPTION,B.PD_ID,B.PD_PRICE FROM TBL_CATEGORY A, TBL_PRODUCT B WHERE A.cat_Parent_ID=$category AND A.CAT_ID=B.CAT_ID ORDER BY B.PD_PRICE"); echo " <br><br> <b> <center> Search Result </center></b>"; $price=$cost; //Backup data $total=0; // Contains Total Cost of the Product while ($record=mysql_fetch_array($res)){ if($record['PD_PRICE'] <= $price) {// Display the Product if within the Price Range echo "<table cellpadding='5', border='5',cellspacing='10' align='center'> <br><b><center>Product Details </center> </b>"; echo "<br><tr> <td> Preview </td> <td> Name </td>"; echo "<td> Description </td>"; echo "<td>Price</td>"; echo "<tr>"; $total=$total + $record['PD_PRICE']; $price=$price - $record['PD_PRICE']; if($record['PD_THUMBNAIL']){ $cat_image=$record['PD_THUMBNAIL']; if($cat_image) // Display product image if found else // Does not display other image echo " <td width='75' align='center'><img src='$cat_image'>"; }// End of Thumbnail IF echo "<b>"; echo "<td>$record[PD_NAME]</td>"; echo "<td>$record[PD_DESCRIPTION]</td>"; echo "<td>$record[PD_PRICE]</td>"; echo "</b>"; echo "</tr>"; $_GET['p']=$record['PD_ID']; //set the product id addToCart(); // Function called }// ENDIF else{ echo "<br><br><marquee bgcolor='red'> <b>No Product in The Category Within the Entered Amount</b></marquee>"; exit; } }// End While echo "</table>"; $_GET['action']='view'; // Passes it on to cart.php echo "<br /><br />"; echo " <div align='right'> "; echo "<form name='form1' method='get' action='cart.php?action=view'>"; echo "<input name='submit' type='submit' value='Checkout' />"; echo "</form>"; echo "</div>"; }// End IF Category }// End IF Submit // Error function present The addtoCart function is as follows:- function addToCart() { // make sure the product id exist if (isset($_GET['p']) && (int)$_GET['p'] > 0) { $productId = (int)$_GET['p']; } else { header('Location: index.php'); } // does the product exist ? $sql = "SELECT pd_id, pd_qty FROM tbl_product WHERE pd_id = $productId"; $result = dbQuery($sql); if (dbNumRows($result) != 1) { // the product doesn't exist header('Location: cart.php'); } else { // how many of this product we // have in stock $row = dbFetchAssoc($result); $currentStock = $row['pd_qty']; if ($currentStock == 0) { // we no longer have this product in stock // show the error message setError('The product you requested is no longer in stock'); header('Location: cart.php'); exit; } } // current session id $sid = session_id(); // check if the product is already // in cart table for this session $sql = "SELECT pd_id FROM tbl_cart WHERE pd_id = $productId AND ct_session_id = '$sid'"; $result = dbQuery($sql); if (dbNumRows($result) == 0) { // put the product in cart table $sql = "INSERT INTO tbl_cart (pd_id, ct_qty, ct_session_id, ct_date) VALUES ($productId, 1, '$sid', NOW())"; $result = dbQuery($sql); } else { // update product quantity in cart table $sql = "UPDATE tbl_cart SET ct_qty = ct_qty + 1 WHERE ct_session_id = '$sid' AND pd_id = $productId"; $result = dbQuery($sql); } // an extra job for us here is to remove abandoned carts. // right now the best option is to call this function here deleteAbandonedCart(); [b]header('Location: ' . $_SESSION['shop_return_url']);[/b] } The warning and error message is as follows and pointing to the following part:- Notice: Undefined index: shop_return_url in f:\program files\easyphp1-8\www\plaincart\library\cart-functions.php on line 71 Warning: Cannot modify header information - headers already sent by (output started at f:\program files\easyphp1-8\www\plaincart\budget.php:19) in f:\program files\easyphp1-8\www\plaincart\library\cart-functions.php on line 71 However when run after the index.php which is the main shopping application the notice dissapears but the warning is present. Quote Link to comment Share on other sites More sharing options...
trq Posted April 18, 2007 Share Posted April 18, 2007 You might want to at least point out which is line 71. Also, read the sticky on header errors, its a very common mistake. Quote Link to comment Share on other sites More sharing options...
rcorlew Posted April 18, 2007 Share Posted April 18, 2007 YOur header problem is becuase you are starting your code on line 2 instead of line 1. Quote Link to comment Share on other sites More sharing options...
riddhi Posted April 18, 2007 Author Share Posted April 18, 2007 This is the line.... header('Location: ' . $_SESSION['shop_return_url']); Quote Link to comment Share on other sites More sharing options...
riddhi Posted April 18, 2007 Author Share Posted April 18, 2007 I am a beginner please make it a bit more clear :'( Quote Link to comment Share on other sites More sharing options...
per1os Posted April 18, 2007 Share Posted April 18, 2007 In order for header's to work NO OUTPUT can be sent to the browser. The notice error is printing data to the browser which in return is throwing off the header because it cannot have any output to the browser to work. So...find out where the notice is being thrown and add something like this <?php if (isset($array['INDEXHERE'])) { // do processing with that index } ?> That way if the index is not set in the array nothing bad happens. Quote Link to comment Share on other sites More sharing options...
riddhi Posted April 20, 2007 Author Share Posted April 20, 2007 Thanks a lot frost110 it seems to have worked Quote Link to comment Share on other sites More sharing options...
riddhi Posted April 20, 2007 Author Share Posted April 20, 2007 Sorry, I thought it worked but now it is again giving error as :- The change I made is:- if (isset($_SESSION['shop_return_url'])) // If it is defined then header('Location: ' . $_SESSION['shop_return_url']); The error it is giving is:- Warning: Cannot modify header information - headers already sent by (output started at f:\program files\easyphp1-8\www\plaincart\budget.php:19) in f:\program files\easyphp1-8\www\plaincart\library\cart-functions.php on line 72 where line 72 is this line:- header('Location: ' . $_SESSION['shop_return_url']); Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 20, 2007 Share Posted April 20, 2007 Line 19 in budget.php is actually the reason you are getting this error. Make sure NO OUTPUT (including whitespaces and newlines) has been sent to the browser before you call a header() function. Quote Link to comment Share on other sites More sharing options...
riddhi Posted April 21, 2007 Author Share Posted April 21, 2007 Thanks Glyde for the help. I have used ob_start() it works and gives no error when used with the extra line :- if(isset(.....)) but unfortunately it works a bit in an unexpected manner . Quote Link to comment Share on other sites More sharing options...
neel_basu Posted April 21, 2007 Share Posted April 21, 2007 Fixed from your first post <?php require_once 'library/config.php'; require_once 'library/cart-functions.php'; if (!defined('WEB_ROOT')) { exit; } ?> [b]// A Dynamic list created with a form for the provision for input [/b] <?php extract($_POST); // Extracts POST Gobal Array extract($_GET); global $total,$price,$pos; if(isset($submit)){ // Checks errors After submission by calling a function//Removed [b] [/b] if(ereg("[0-9]",$category)){ // Checks Numeric Entry by user $res=dbQuery("SELECT B.PD_THUMBNAIL,B.PD_NAME, B.PD_DESCRIPTION,B.PD_ID,B.PD_PRICE FROM TBL_CATEGORY A, TBL_PRODUCT B WHERE A.cat_Parent_ID=$category AND A.CAT_ID=B.CAT_ID ORDER BY B.PD_PRICE"); echo " <br><br> <b> <center> Search Result </center></b>"; $price=$cost; //Backup data $total=0; // Contains Total Cost of the Product while ($record=mysql_fetch_array($res)){ if($record['PD_PRICE'] <= $price) {// Display the Product if within the Price Range echo "<table cellpadding='5', border='5',cellspacing='10' align='center'> <br><b><center>Product Details </center> </b>"; echo "<br><tr> <td> Preview </td> <td> Name </td>"; echo "<td> Description </td>"; echo "<td>Price</td>"; echo "<tr>"; $total=$total + $record['PD_PRICE']; $price=$price - $record['PD_PRICE']; if($record['PD_THUMBNAIL']){ $cat_image=$record['PD_THUMBNAIL']; if($cat_image) { //Display product image if found //Curly Braces of if were mising so added those } else // Does not display other image echo " <td width='75' align='center'><img src='$cat_image'>"; }// End of Thumbnail IF echo "<b>"; echo "<td>$record[PD_NAME]</td>"; echo "<td>$record[PD_DESCRIPTION]</td>"; echo "<td>$record[PD_PRICE]</td>"; echo "</b>"; echo "</tr>"; $_GET['p']=$record['PD_ID']; //set the product id addToCart(); // Function called }// ENDIF else{ echo "<br><br><marquee bgcolor='red'> <b>No Product in The Category Within the Entered Amount</b></marquee>"; exit; } }// End While echo "</table>"; $_GET['action']='view'; // Passes it on to cart.php echo "<br /><br />"; echo " <div align='right'> "; echo "<form name='form1' method='get' action='cart.php?action=view'>"; echo "<input name='submit' type='submit' value='Checkout' />"; echo "</form>"; echo "</div>"; }// End IF Category }// End IF Submit // Error function present ?> Quote Link to comment Share on other sites More sharing options...
neel_basu Posted April 21, 2007 Share Posted April 21, 2007 <?php function addToCart() { // make sure the product id exist if (isset($_GET['p']) && (int)$_GET['p'] > 0) { $productId = (int)$_GET['p']; } else { header('Location: index.php'); } // does the product exist ? $sql = "SELECT pd_id, pd_qty FROM tbl_product WHERE pd_id = $productId"; $result = dbQuery($sql); if (dbNumRows($result) != 1) { // the product doesn't exist header('Location: cart.php'); } else { // how many of this product we // have in stock $row = dbFetchAssoc($result); $currentStock = $row['pd_qty']; if ($currentStock == 0) { // we no longer have this product in stock // show the error message setError('The product you requested is no longer in stock'); header('Location: cart.php'); exit; } } // current session id $sid = session_id(); // check if the product is already // in cart table for this session $sql = "SELECT pd_id FROM tbl_cart WHERE pd_id = $productId AND ct_session_id = '$sid'"; $result = dbQuery($sql); if (dbNumRows($result) == 0) { // put the product in cart table $sql = "INSERT INTO tbl_cart (pd_id, ct_qty, ct_session_id, ct_date) VALUES ($productId, 1, '$sid', NOW())"; $result = dbQuery($sql); } else { // update product quantity in cart table $sql = "UPDATE tbl_cart SET ct_qty = ct_qty + 1 WHERE ct_session_id = '$sid' AND pd_id = $productId"; $result = dbQuery($sql); } // an extra job for us here is to remove abandoned carts. // right now the best option is to call this function here deleteAbandonedCart(); //Removed [b][/b] header('Location: ' . $_SESSION['shop_return_url']); } ?> Quote Link to comment Share on other sites More sharing options...
neel_basu Posted April 21, 2007 Share Posted April 21, 2007 Dont send anything to the output buffer channel even no echo beforesending header informations to the browser. So you need to use header() at the very begening of your codes. Quote Link to comment Share on other sites More sharing options...
riddhi Posted April 21, 2007 Author Share Posted April 21, 2007 Please tell me about the changes made ? Quote Link to comment Share on other sites More sharing options...
neel_basu Posted April 21, 2007 Share Posted April 21, 2007 I've comented the bugs out Search for this following texts on your code //Removed //Curly Braces of if were mising so added those Quote Link to comment 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.