Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "toets2";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- // prepare sql and bind parameters
- $stmt = $conn->prepare("INSERT INTO toets2 (voornaam, tussenvoegsel, achternaam, email)
- VALUES (:voornaam, :tussenvoegsel, :achternaam, :email)");
- $stmt->bindParam(':voornaam', $voornaam);
- $stmt->bindParam(':tussenvoegsel', $tussenvoegsel);
- $stmt->bindParam(':achternaam', $achternaam);
- $stmt->bindParam(':email', $email);
- // insert a row
- $voornaam = "John";
- $achternaam = "Doe";
- $tussenvoegsel = "Test";
- $email = "john@example.com";
- $stmt->execute();
- // insert another row
- $voornaam = "Mary";
- $achternaam = "Moe";
- $tussenvoegsel = "Test";
- $email = "mary@example.com";
- $stmt->execute();
- // insert another row
- $voornaam = "Julie";
- $achternaam = "Dooley";
- $tussenvoegsel = "Test";
- $email = "julie@example.com";
- $stmt->execute();
- echo "New records created successfully";
- }
- catch(PDOException $e)
- {
- echo "Error: " . $e->getMessage();
- }
- $conn = null;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement