Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <form action="index.php" method="post">
- Name: <input type="text" name="name"><br>
- E-mail: <input type="text" name="email"><br>
- <input type="submit">
- </form>
- </body>
- </html>
- <?php
- /*** mysql hostname ***/
- $hostname = 'localhost';
- /*** mysql username ***/
- $username = 'username';
- /*** mysql password ***/
- $password = 'password';
- try {
- $dbh = new PDO("mysql:host=$hostname;dbname=animals", $username, $password);
- /*** set the error reporting attribute ***/
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- /*** prepare the SQL statement ***/
- $stmt = $dbh->prepare("INSERT name=:name, email=:email INTO user");
- /*** bind the paramaters ***/
- $stmt->bindParam(':name', $_POST["name"], PDO::PARAM_STR);
- $stmt->bindParam(':email', $_POST["email"], PDO::PARAM_STR);
- /*** execute the prepared statement ***/
- $stmt->execute();
- /*** close the database connection ***/
- $dbh = null;
- }
- catch(PDOException $e) {
- echo $e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement