Jump to content

Header error


corbeeresearch

Recommended Posts

Hi, I'm a newbie, and needed help fixing a part of a code

 

Whenever someone is clicking add to cart, it triggers an error.

 

The output is:

Duplicate entry
Warning: Cannot modify header information - headers already sent by (output started at C:\ampp\htdocs\ptc1\pages\insertTotempsql.php:9) in C:\ampp\htdocs\ptc1\pages\insertTotempsql.php on line 56

 

Is there some weakness in the code causing it? line 56 is the last line.

The code is

<?php 
if( !isset( $_SESSION )){
session_start();

      
}   $ses_id = session_id(); 
require_once('../Connections/connect.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php

if(isset($_POST['id'])){
$id=$_POST['id'];
$uom=$_POST['uom'];

$quantity=$_POST['QUANTITY'];
$date=$_POST['dateToday'];
$PRICE=$_POST['PRICE'];

if(isset($_POST['MeatOrigin'])){

$prod=$_POST['prodname'] . " ( " . $_POST['MeatOrigin'] . " ) ";

}
else {
$prod=$_POST['prodname'];
}
mysql_select_db($database_connect, $connect);
//check database if item is existing

$query_duplicate = sprintf("SELECT * FROM tbl_cart WHERE pd_id='$id' and ct_session_id='$ses_id' and ct_date='$date'");
$duplicate = mysql_query($query_duplicate, $connect) or die(mysql_error());
$row_duplicate = mysql_fetch_assoc($duplicate);
$totalRows_duplicate = mysql_num_rows($duplicate);


if($totalRows_duplicate > 0){

echo "Duplicate entry";
}

else
{

$insertSQL = "INSERT INTO tbl_cart ( pd_id, pd_name, ct_qty, ct_session_id, ct_date, PRICE, uom) VALUES ('$id', '$prod', '$quantity', '$ses_id', '$date', '$PRICE', '$uom')";

  
$Result1 = mysql_query($insertSQL, $connect) or die(mysql_error());
}

  


  
mysql_close($connect);

header("Location:".$_SERVER['HTTP_REFERER']);
}
?>

 

Thanks

Link to comment
Share on other sites

Remove the DOCTYPE line, since it's not needed as there is no HTML output.  You can not send any output to the browser before you do a header() function and the DOCTYPE line is output. You will also can't echo the error message. What good is a error message when the header loads another page and the user wouldn't see it?

 

Ken

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.