Multi Purpose Form Problems with SQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gjb79
Forum Commoner
Posts: 96
Joined: Fri Jul 18, 2003 6:35 am
Location: x <-- (DC)
Contact:

Multi Purpose Form Problems with SQL

Post by gjb79 »

:idea: As the subject hints, I'm having problems getting a form to do multiple things. I am building a website that has a special web service. The website has a SQL database which holds information people submit when they sign up for the service. I created a content management system that allows administrators to view the records, edit the info, add records, and remove them easily.

:arrow: It has now been put upon me to modify the form to email the entered data to the client in additon to add it to the database.

:?: I have looked up just about all I could with regards to php, email, web forms, and sql. I do not see how this could possibly happen, though I hold a firm belief that it is possible. I am having trouble wraping my mind around a form that executes two actions at the same time.

Any help would be wonderful
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

Actually fairly simple. Once you add the information to the database, then send an email. Example:

Code: Select all

<?
$sql = "INSERT INTO table SET information_etc ='$information_etc";
if(@mysql_query($sql)) {

	$from="support@email.com";
	$to="$form_email";
	$message="this is your message. Add $form_variables_here_also";
	$message = stripslashes ($message);
	if(mail($to,"subject",$message,"From: $from")) {
	echo ("email sent");
	} else {
	echo ("There was a problem sending the mail.");
	}
	echo ("Confirm message here. added to database");
		} else {
			echo("Error adding > " . mysql_error() . " < that error"); 
		}

?>
Hope that helps. (kinda took the code and diced it up a bit. Just an example)
User avatar
gjb79
Forum Commoner
Posts: 96
Joined: Fri Jul 18, 2003 6:35 am
Location: x <-- (DC)
Contact:

I see

Post by gjb79 »

That looks good, but out of curiosity, which line exactly submits the email?

I see you spell out the to from subject content parts but shouldn't there be an execute statement that sends it? Or is that what happens when you evaluate it with:

if(mail($to,"subject",$message,"From: $from")) {

Using email with php is something I haven't much experience with, yet, so I really appreciate your help. I'm sure this will be enough to continue my research on the subject.

Thank you!
Post Reply