Solved

INSERT INTO MySql db and send email

Posted on 2004-09-14
6
307 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 100 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now