Solved

INSERT INTO MySql db and send email

Posted on 2004-09-14
6
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

617 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