Created
June 26, 2014 12:45
-
-
Save samroar/49099985bc86d9f195da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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