Hi all,
Just wondering if someone can help me with the following - I would like to send a web form to not only email but a MySQL database.
Below is a sudo form:
<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>
And this is the PHP script for sending the Form:
<?php
//Some variables
$mymail = "myemail@address.com";
$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>";
}
}
?>
If I was to use something like the following for the post to DB:
<?
$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.";
?>
Can someone please tell me how I would add this to the PHP code (example would be great based on the code given).
Many thanks