Page 1 of 1

Multi Purpose Form Problems with SQL

Posted: Tue Aug 19, 2003 7:59 pm
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

Posted: Tue Aug 19, 2003 10:32 pm
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)

I see

Posted: Wed Aug 20, 2003 12:31 pm
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!