PHP: Create query statement
<html>
<head>
</head>
<?php
//variables
$hostname='localhost';
$username='root';
$password='Marion9197';
$dbname='favorites';
try{
//connection
$conn=new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//template - prepared statement
$stmt=$conn->prepare("INSERT INTO stuff (color, movie, car, food) VALUES (:color, :movie, :car, :food)");
//parameter bindings
$stmt->bindParam(':color', $color);
$stmt->bindParam(':movie', $movie);
$stmt->bindParam(':car', $car);
$stmt->bindParam(':food', $food);
//parameter definitions
$color=$_POST['color'];
$movie=$_POST['movie'];
$car=$_POST['car'];
$food=$_POST['food'];
$stmt->execute();
}
catch(PDOException $e){
echo $e->getMessage();
}
$conn=null;
?>
<p><a href="ks005c.php" >List</a></p>
</body>
</html>
No comments:
Post a Comment