Reputation: 336
This day is my first time using PDO. And when I try 'INSERT' with PDO, it does nothing.
This is my code :
session_start();
if($_GET['feedback']!="")
{
$fb = $_GET['feedback'];
$date = date('Y-m-d H:i:s');
$query = "INSERT INTO feedback(number, sender, content, date) VALUES (NULL,?,?,?)";
$STH = $DBH->prepare($query);
$STH->bindParam(1, $_SESSION['alias']);
$STH->bindParam(2, $fb);
$STH->bindParam(3, $date);
$STH->execute();
}
I have tried a 'SELECT' query with PDO and it works. What should I do?
Upvotes: 0
Views: 2139
Reputation: 157828
What should I do?
Error reporting.
Check tag wiki for the example.
It is essential to set ERRMODE_EXCEPTION as a connection option as it will let PDO throw exceptions on connection errors. Setting ATTR_DEFAULT_FETCH_MODE is also a good idea.
Please note that connection errors shouldn't be catched, at least not using try..catch operator. A custom exception handler could be used, but not required. Especially for new users, it is okay to have unhandled exceptions, as they are extremely informative and helpful.
Upvotes: 0
Reputation: 930
why dont you try and enclose your code in try and catch blocks to get any exceptions:
try {
//your code
} catch( PDOEXception $e ) {
echo $e->getMessage(); // display error
exit();
}
This should give you a clue whats going wrong.
Upvotes: 2