Inserting a date into a table using PDO

Jim

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

meda

@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);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Inserting date into mysql table using shell script

From Dev

PHP: Inserting date into a table

From Dev

Inserting Data to MySQL using PDO for PHP Xcode

From Dev

Using PDO to CREATE TABLE

From Dev

PDO query does not return data when inserting date as variable

From Dev

Inserting into MySQL table using a variable

From Dev

Inserting data into table using java

From Dev

Inserting into a table in mysql using query

From Dev

Stop a Null value date inserting in the table when the textbox value is null using C#

From Dev

Inserting Current Date as default in MySQL table

From Dev

Inserting date/time in a SQL table in SAS

From Dev

inserting autoincrement and current date time in a table

From Dev

Inserting Current Date as default in MySQL table

From Dev

Inserting data to mysql database using PDO with direct insert statement

From Dev

More efficient way of inserting data into mysql using PDo

From Dev

Inserting data to mysql database using PDO with direct insert statement

From Dev

If statement is not working when inserting data using PHP PDO Prepared statements

From Dev

html form data is not inserting in MySQL database using PHP and PDO

From Dev

Inserting date in oracle database using Php

From Dev

Inserting a date in a Oracle SP using PHP

From Dev

Inserting date in mysql databate using java

From Dev

Inserting a column conditionally based on date using VBA

From Dev

trouble inserting PDO

From Dev

PDO inserting double data

From Dev

PDO inserting data

From Dev

PDO inserting and updating

From Dev

Issue with inserting data PDO

From Dev

inserting row in the middle of a html table using javascript

From Dev

Randomly inserting images into table using Javascript

Related Related

HotTag

Archive