Hi all,
Just wondering if someone can help me with the following - I would like to send my web form to not only email but to a MySQL DB. I have the following code for all of the above and now need help on how to bring it all together to achieve what I have outlined above.
Web Form:
PHP Code to Send Form:HTML Code:<div> <form name="contact" method="post" action="contactprocess.php"> <strong>Name:</strong><br/> <input type="text" name="ename" size="30"><br/> <strong>Email:</strong><br/> <input type="text" name="eemail" size="30"><br/> <strong>Subject:</strong><br/> <input type="text" name="esubject" size="30"><br/> <strong>Message:</strong><br/> <textarea name="emessage" cols="30" rows="10"></textarea><br/> <input type="submit" name="esubmit" value="Send Mail" style="cursor:pointer"> <input type="hidden" name="eip" value="<?php echo $_SERVER["REMOTE_ADDR"]; ?>"> </form> </div>
Possible PHP code to send Form to DB:PHP Code:<?php
//Some variables
$mymail = "[email protected]";
$ename = $_POST['ename'];
$eemail = $_POST['eemail'];
$esubject = $_POST['esubject'];
$emessage = $_POST['emessage'];
$eip = $_POST['eip'];
//Function to check email address
function checkemail($eemail) {
if(eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$eemail)) {
return true;
}
else {
return false;
}
}
//Mail Processing
if ($_POST['esubmit']) {
//Check for blank fields
if ($ename == "" || $eemail == "" || $esubject == "" || $emessage == "") {
echo "<p>It appears that you left a blank field.<br/> Please make sure you fill everything in.</p>";
}
//Check to see if the email address is valid
else if (checkemail($eemail) == false) {
echo "<p>It appears that you enter an invalid email address.<br/> Please check your email again.</p>";
}
//Send the email if there's no error
else {
$body = "$emessage\n\nName: $ename\nEmail: $eemail\nIp: $eip";
mail($mymail,$esubject,$body,"From: $eemail\n");
echo "<p>Thank you for your email $ename!</p>";
}
}
?>
Can someone please help me bring the form and DB script together based on the above (an example based on the code used would be great).PHP Code:<?
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ('$name', '$email','subject','$message')");
Print "Your information has been successfully added to the database.";
?>
Many thanks




Reply With Quote