Reputation: 1315
I have a PDO insert statement that is not inserting the information and I am at a loss as to why. Here is my statement:
$log = $conn->prepare("insert into log_activity (user, event, date) values(:who, :event, :date)");
$log->bindParam(":who", $name, PDO::PARAM_INT);
$log->bindParam(":event", $event, PDO::PARAM_STR);
$log->bindParam(":date", $date, PDO::PARAM_STR);
$log->execute();
I use a similar one (just no date) for registration that works perfectly. Here is the values:
$name = $_POST['name'];
$event = $_POST['thing'];
$date = $_POST['date'];
I know there are values there, and I am not throwing an error statement. I have tried removing the date thinking that it might be the issue and it still does not work. I am sure I am just missing something easy, but can't find it.
Thanks
Upvotes: 1
Views: 103
Reputation: 45490
@Jim is $name
really of type INT
?
You can leave it up to PDO to determine the type you know, you don't have to be explicit
$log = $conn->prepare("insert into log_activity (user, event, date) values(:who, :event, :date)");
$log->bindParam(":who", $name);
$log->bindParam(":event", $event);
$log->bindParam(":date", $date);
$log->execute();
Or just dont bind:
$log = $conn->prepare("insert into log_activity (user, event, date) values(:who, :event, :date)");
$log->execute(array(':who'=>$name, ':event' => $event, ':date'=> $date));
Make sure your connection is set to throw errors:
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Upvotes: 1
Reputation: 2364
You are missing ,
in the first line after :event
. Maybe that's the problem.
Upvotes: 0