Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "choodida";
- $dbname = "mydb";
- 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);
- $stmt = $conn->prepare("INSERT INTO MyGuests (name, age, sex,result)
- VALUES (:name, :age, :sex,:result)");
- $stmt->bindParam(':name', $name);
- $stmt->bindParam(':age', $age);
- $stmt->bindParam(':sex', $sex);
- $stmt->bindParam(':result', $result);
- $name = $_POST["name"];
- $age = $_POST["age"];
- $sex = $_POST["sex"];
- $result = $_POST["result"];
- // use exec() because no results are returned
- $stmt->execute();
- echo "New record created successfully";
- }
- catch(PDOException $e)
- {
- echo $sql . "<br>" . $e->getMessage();
- }
- $conn = null;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement