Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "127.0.0.1";
- $username = "root";
- $password = "hagrid";
- $dbname = "kitsune";
- //making an array with the data recieved, to use as named placeholders for INSERT by PDO.
- $data = array('name' => $_POST['name'] , 'lotteryNumber' => $_POST['lottery'] , 'email' => $_POST['email']);
- try {
- // preparing database handle $dbh
- $dbh = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- // query with named placeholders to avoid sql injections
- $query = "INSERT INTO lottery (name, lottery, email) VALUES (:name, :lottery, :email )";
- //statement handle $sth
- $sth = $dbh->prepare($query);
- $sth->execute($data);
- echo "New record created successfully";
- }
- catch(PDOException $e)
- {
- echo $sql . "<br>" . $e->getMessage();
- }
- $dbh = null;
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Enter the Lottery!</title>
- </head>
- <body>
- <form action="insert.php" method="post">
- <p>
- <label for="name">Name:</label>
- <input type="text" name="name" id="name">
- </p>
- <p>
- <label for="lotteryNumber">Your Lottery Number:</label>
- <input type="text" name="lotteryNumber" id="lotteryNumber">
- </p>
- <p>
- <label for="email">Your Email Address:</label>
- <input type="text" name="email" id="email">
- </p>
- <input type="submit" value="Enter With Good Luck">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement