I'm at a loss here. I'm trying to insert a row into a table with PDO, but it simply doesn't work. I always do it this way with other tables and it never gave any problems! Maybe it has something to do with the table... Anwyway, my script looks like this:
<?php
// Connect to DB.
$hostname = "localhost";
$database = "website";
$username = "leon";
$password = "B6T8WGfs";
try
{
$connect = new PDO("mysql:host=$hostname; dbname=$database; charset=utf8", $username, $password) or die("Kan geen verbinding maken met database!");
}
catch (Exception $e)
{
throw new Exception( 'Error connecting to database: ', 0, $e);
}
#### Prepare variables for PDO.
$user_id=28; // will change this later
$university=$_POST['university'];
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$order_items=$_POST['message']; // will change this later
$sent='false';
#### Add order to database.
try {
$add_order=$connect->prepare("INSERT INTO orders(user_id, university, name, email, message, order_items, sent)VALUES(:user_id, :university, :name, :email, :message, :order_items, :sent)");
$add_order->execute(array(':user_id'=>$user_id,
':university'=>$university,
':name'=>$name,
':email'=>$email,
':message'=>$message,
':order_items'=>$order_items,
':sent'=>$sent));
echo "Success";
}
catch(PDOException $ex) {
echo "An Error occured!"; //user friendly message
echo ($ex->getMessage());
}
$connect = null;
?>
It seems to work, because the output on the page says "Success". But in fact, the row is not added to the table. My MYSQL 'orders' table looks like this:
NOTE: In the Browse (Verkennen) tab there's one row, that I entered manually to test whether it was possible to enter something in the table at all.
Any help would be much appreciated!