Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

INSERT INTO MySql db and send email

Posted on 2004-09-14
6
Medium Priority
?
317 Views
Last Modified: 2013-12-12
Hi,

I want to send form elements to MySQL db and my inbox too. I have this script:
********************************************

<?
$usr = "username";
$pwd = "password";
$db = "dbname";
$host = "localhost";
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
if ($REQUEST_METHOD=="POST") {
$SQL = " INSERT INTO orders ";
$SQL = $SQL . " (id, colour, colour2, package, delday, delmonth, delyear, deltime, card, comments, fname, sname, address, zip, city, directions, phone, pay, cctype, cc1, cc2, cc3, cc4, ccexpmonth, ccexpyear, cvv2, payfname, paysname, payaddress, payphone,  email, more) VALUES ";
$SQL = $SQL . " ('$first', '$colour', '$colour2', '$package', '$delday', '$delmonth', '$delyear', '$deltime', '$card', '$comments', '$fname', '$sname', '$address', '$zip', '$city', '$directions', '$phone', '$pay', '$cctype', '$cc1', '$cc2', '$cc3', '$cc4', '$ccexpmonth', '$ccexpyear', '$cvv2', '$payfname', '$paysname', '$payaddress', '$payphone', '$email', '$more') ";
$result = mysql_db_query($db,"$SQL",$cid);
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
}
mysql_close($cid);
?>

<?
  $from = "Mysite.com <>";

  $message .= $package;
  $message .= $colour;

  mail( "admin@mydomain.com", "order", $message, "From: $from");
  header( "Location: thanks.php" );
?>

*******************************************

...but I take this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/order/process.php:3) in /home/public_html/order/process.php


Can anybody help, please? Where is the problem?
0
Comment
Question by:MZ_24976
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:AlanJDM
ID: 12055837
This error is caused by trying to send output to the browser(headers) more than once in a script. In your case you are calling the header() function after some form of output has already been sent to the browser. Is this the entire script?


Alan
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 12055880
Note:  even if there is no specific HTML content echoed or printed out to the browser in this script, a whitespace will cause this error.

For example:

-----------------------------------------------------------------------------

<?
    // code here, notice space between top of page and start of php
?>
-----------------------------------------------------------------------------

Would cause an error, while this would not:

-----------------------------------------------------------------------------
<?
    // code here, notice space between top of page and start of php
?>
-----------------------------------------------------------------------------


Notice the skipped line in the first example.
0
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 400 total points
ID: 12055893
Note 2: skipped lines WITHIN <? ?> tags will not cause this error.  The following is valid:

-----------------------------------------------------------------------------
<?



    // code here, notice space between top of page and start of php



?>
-----------------------------------------------------------------------------
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MZ_24976
ID: 12056272
Thanks!
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 12056298
Should have been shared points, IMO :-/
You're welcome for the help.
0
 
LVL 9

Expert Comment

by:AlanJDM
ID: 12057054
wow
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question