Skip to content

Instantly share code, notes, and snippets.

@samroar
Created July 17, 2014 16:22
Show Gist options
  • Select an option

  • Save samroar/66dd5600e47f5a6401aa to your computer and use it in GitHub Desktop.

Select an option

Save samroar/66dd5600e47f5a6401aa 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 action="posts.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" />
<label for ='user'>user</label>
<input type="text" name="user" />
<label for ='url'>url</label>
<input type="text" name="url" />
<input type="submit">
</form>
</body>
</html>
php
<?php
if(!empty($_POST)) {
$dbh = new PDO('mysql:dbname=reddit;host:localhost', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
$query = $dbh->prepare('INSERT INTO posts (title, subreddit, user, url) VALUES (?, ?, ?, ?)');
$query->execute(array($_POST['title'], $_POST['subreddit'], $_POST['user'], $_POST['url']));
echo $_POST['title'];
echo $_POST['subreddit'];
echo $_POST['user'];
echo $_POST['url'];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment