Solved

INSERT INTO MySql db and send email

Posted on 2004-09-14
6
306 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 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

16 Experts available now in Live!

Get 1:1 Help Now