Skip to content

Instantly share code, notes, and snippets.

@theWhiteFox
Created July 9, 2014 12:36
Show Gist options
  • Save theWhiteFox/36abe197ab272ffcc5e6 to your computer and use it in GitHub Desktop.
Save theWhiteFox/36abe197ab272ffcc5e6 to your computer and use it in GitHub Desktop.
Contact page HTML5 - PDO - MySQL - localhost - WAMP
<article id = "page-contact" class="page-round">
<!-- Contact -->
<header>
<h2>Contact</h2>
</header>
<p>Email [email protected]</p>
<?php
if (isset($_POST['submit'])) {
$dbh = new PDO('mysql:host=localhost;dbname=register', 'root', '', array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC));
try {
$stmt = $dbh->prepare("INSERT INTO registered(Name, Email, Message) values (?,?,?)");
$stmt->bindParam(1, $name);
$stmt->bindParam(2, $email);
$stmt->bindParam(3, $message);
$human = $_POST['human'];
if ($human == '4') {
if (empty($_POST["name"])) {
} else {
$name = $_POST["name"];
}
if (empty($_POST["email"])) {
} else {
$email = $_POST["email"];
}
if (empty($_POST["message"])) {
} else {
$message = $_POST["message"];
}
} else {
echo '<b><p><font color="red">Something went wrong, please and try again!</font></p></b>';
}
$stmt->execute();
echo'<b><p><font color="green">Thank you, I will contact you soon!</font></p></b>';
} catch (PDOException $e) {
if ($e->errorInfo[1] == 1048) {
echo '<b><p><font color="red">You missed either name, spam, message or email.</font></p></b>';
} elseif ($e->errorInfo[1] == 1062) {
// duplicate entry, do something else
echo '<b><p><font color="red">This email has already been added!</font></p></b>';
} else {
// an error other than duplicate entry occurred
echo "Exception caught: $e";
}
}
}
?>
<form method="post" action="#page-contact">
<label class="name">Name</label>
<input class="name" name="name" type="name" placeholder="Type Here">
<label class="email">Email</label>
<input class="email" name="email" type="email" placeholder="Type Here">
<label class="human">*What is 2+2? (Anti-spam)</label>
<input class="human" name="human" placeholder="Type Here">
<div id="message">
<label>Message</label>
<textarea name="message" type="message" placeholder="Type Here"></textarea>
<input id="submit" name="submit" type="submit" value="submit">
</div>
</form>
<nav class="next-prev">
<a class="prev page-projects" href="#page-projects">Menu<img class="arrow-up"></img></a>
<hr />
<a class="next page-about" href="#page-about">Next<img class="arrow"></img></a>
</nav>
</article>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment