I want to have a page where a user can insert their contact form (name, address, city, zip, email etc.). Their info will be stored in MyPhpAdmin database in a table. Is it possible to do it within wordpress template? I have a template specifically called template-join-us.php for this.
I inserted these codes in the template right after the if (have_post()) loop:
<? if ( $_POST['email'] ) { ?>
<center>Thank you. You will be receiving a confirmation e-mail shortly.</center>
<? } else { ?>
<form action="index.php?page_id=4" method="post"> --> this is the location of submission
Name: <input type="text" name="name" /><br />
Address: <input type="text" name="address" /><br />
City: <input type="text" name="city" /><br />
State: <input type="text" name="state" /><br />
Zip: <input type="text" name="zip" /><br />
Email: <input type="text" name="email" /><br />
Phone: <input type="text" name="phone" /><br />
<br />
<input type="submit" name="submit" value="submit" />
</form>
<? } ?>
<? if ( $_POST['email'] ) {
include_once("db.php"); --> to call localhost database to insert the contact form data
$query = "INSERT INTO contact_form (<code>name</code>, <code>address</code>, <code>city</code>, <code>state</code>, <code>zip</code>, <code>email</code>, <code>phone</code>, <code>stamp</code>) VALUES ('".$_POST['name']."', '".$_POST['address']."', '".$_POST['city']."', '".$_POST['state']."', '".$_POST['zip']."', '".$_POST['email']."', '".$_POST['phone']."', NOW() )";
$result = mysql_query($queryb) or die("Query Error: ".mysql_error());
$emailsend = strval($_POST['email']);
Code below is to change sender's email address to string so that the confirmation email will also be sent to sender's email as seen below
if ( $result ) { mail( 'myself@myself.com' , 'Insert Header Topic Here' , 'Insert Email Content Here', 'From: webmaster@myself.com' . "\r\n" .
'Reply-To: webmaster@myself' . "\r\n" .
'X-Mailer: PHP/' . phpversion());
}
mysql_close($db);
}
?>
I tried this code then did a test submission, then the page just gives a blank result with warning: "Sorry, no posts matched your criteria."
What's wrong? How to fix it?