So it's been awhile since I used PHP so I am asking for some help. I gave it a good shot but for whatever reason my form is not posting to my database. I hit submit and form clears. I do not receive any errors but database remains empty.
Any help or suggestions are appreciated.
Here is my HTML
<form id="contact-form" method="post">
<div>
<label> <span>Name: *</span>
<input type="text" tabindex="1" name="postName" required autofocus />
</label>
</div>
<div>
<label> <span>Email: *</span>
<input type="email" tabindex="2" name="postEmail" required />
</label>
</div>
<div>
<label> <span>Telephone:</span>
<input type="tel" tabindex="3" name="postPhone"/>
</label>
</div>
<div>
<label> <span>Message: *</span>
<textarea placeholder="Include all the details you can" tabindex="5" name="postMessage" required></textarea>
</label>
</div>
<div>
<input name="formSubmit" type="submit" id="contact-submit" value="Submit" />
</div>
</form>
Here is my PHP
<?php
//show all possible errors. should be ALWAYS set to that level
error_reporting(E_ALL);
echo "landed at form handler<br>";
// sometimes buttons not being sent or gets misspelled
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
echo "here goes POST processing<br>";
$host = 'localhost';
$username = 'name';
$pass = 'password';
$dbname = 'dbname';
mysql_connect($host,$username,$pass);
mysql_select_db($dbname);
// all strings should be escaped
// and it should be done after connecting to DB
$name = mysql_real_escape_string($_POST['postName']);
$email = mysql_real_escape_string($_POST['postEmail']);
$phone = mysql_real_escape_string($_POST['postPhone']);
$message = mysql_real_escape_string($_POST['postMessage']);
$query = "INSERT INTO ContactUs
(NAME, EMAIL, PHONE, MESSAGE)
VALUES ('$name','$email','$phone','$message')";
echo $query;
// always run your queries this way to be notified in case of error
$result = mysql_query($query) or trigger_error(mysql_error().". Query: ".$query);
var_dump($result);
}
?>
type="text"instead, not fortextareathough, just the inputs. Many a times, that's what it is, and I have seen it happen before. Another thingerror_reporting(E_ALL);try addingini_set('display_errors', 1);below that.