Skip to content

Instantly share code, notes, and snippets.

@samroar
Created June 26, 2014 12:45
Show Gist options
  • Select an option

  • Save samroar/49099985bc86d9f195da to your computer and use it in GitHub Desktop.

Select an option

Save samroar/49099985bc86d9f195da to your computer and use it in GitHub Desktop.
html
<!DOCTYPE HTML>
<html>
<head>
<title>reddit: the front page of the internet</title>
<link href="reddit.css" rel="stylesheet"/>
<script src ="reddit.js" type="text/javascript"></script>
</head>
<body>
<form>
<form action="http://localhost/reddit/redditform.php" method="post">
<label for 'id'>id</label>
<input type="number" name="id">
<label for 'title'>title</label>
<input type="text" name="title">
<label for 'sub'>Subreddit</label>
<input type="text" name="subreddit">
<input type="submit">
</form>
</body>
</html>
php
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=reddit', 'root', "");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$form = $_POST;
$id=$form['id'];
$title=$form['title'];
$sql="INSERT INTO posts (id, title) VALUES (:id, :title)";
$query = $dbh->prepare($sql);
$query->execute(array('id'=>$id, ':title'=>$title));
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "</br>";
die();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment