I am trying to figure out why this wont work I had it working with adding just one entry off of the form and then added email and it broke it. Also is this safe from SQL Injection? Here is the error message
ERROR: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
Here is my code for insert.php:
<?php
try {
$conn = new PDO('mysql:host=localhost;dbname=info', 'blah', 'test');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('INSERT INTO people (name, email) VALUES (:name, :email)');
$stmt->bindParam(':name', $POST_['name']);
$stmt->bindParam(':email', $_POST['email']);
$stmt->execute(array(':name' => $_POST['name']));
$stmt->execute(array(':email' => $_POST['email']));
#If one or more rows were returned...
} catch(PDOException $e){
echo'ERROR: ' . $e->getMessage();
}
?>
Here is the working code if I am inserting only one value from the form:
<?php
try {
$conn = new PDO('mysql:host=localhost;dbname=encorem2_info', 'encorem2', 'Yamaha!32088!');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('INSERT INTO people (name) VALUES (:name)');
$stmt->execute(array(':name' => $_POST['name']));
#If one or more rows were returned...
} catch(PDOException $e){
echo'ERROR: ' . $e->getMessage();
}
?>
Here is my html code in separate file:
<!DOCTYPE html>
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<form action="insert.php" method="post">
Name: <input type="text" name="name" id="name" />
Email: <input type="text" name="email" id="email"/>
<input type="submit" />
</form>
</body>
</html>