PDA

View Full Version : Contact form that sends to email and also MySQL




jdl8422
Jun 19, 2008, 05:38 PM
well I have an online survey I am doing for my company. Currently the page is in html/css and the form is in php. I have it to where it sends the data to an email. I would also like for it to go to a MySQL database as well as the email. Other than setting the database up on the server, what code would I need to get it to go to both. Also, I am not here looking for someone to do it for me:D. I just need some direction. Thanks in advance.



Me1000
Jun 19, 2008, 06:07 PM
$tableName = formData; //this is the name of the table in the DB

//your post data...
$name = $_POST['NAME'];
$phone = $_POST['PHONE'];
$addy = $_POST['ADDY'];

//the actual SQL
$sql = "INSERT INTO $TableName (NAME,PHONE, ADDY) VALUES ('$name', '$phone', '$addy')";

$result = mysql_query($sql); //define a var for the query for simplicity sake
$response = ($result) ? 'Entry Added' : 'Entry FAILED!'; //test to see if the query was successful to replay a message back to the user...
echo $response; // print the message back to the user, this is also required to execute the query...


I haven't tested any of that, I just wrote it off the top of my head, but that should work...

jdl8422
Jun 27, 2008, 10:15 AM
Once I have the database set up and the emails go to it, can I input my current emails to it?

Me1000
Jun 27, 2008, 12:56 PM
yes, there is no reason you shouldnt be able to...