Solved

INSERT INTO MySql db and send email

Posted on 2004-09-14
6
312 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
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 …

751 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