Jump to content

Warning and Error message


riddhi

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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']);

 

Link to comment
Share on other sites

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 
?>

Link to comment
Share on other sites

<?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']);				
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.