Sql calculates date instead of inserting

Asked

Viewed 33 times

-1

I’m trying to insert date in my BD but sql calculates the result is always 1997 in the fields I tested as "date" and did not insert "varchar e text" resulted in a subtraction calculation of the current date

$conn = new PDO('mysql:host=localhost;dbname=data', 'root');

   $query = 'INSERT INTO codes (code,dt) VALUES ('.$generator.','.$data_atual.')';

?>

  • @Francis a simple question and this uproar, if you don’t want to help, don’t help simple !!

1 answer

0


Missing parentheses in sql. No need to use dots on variables: if you use single quotes on variables, then use double quotes on the SQL line. PDO has to prepare before executing.

$query = $conn -> prepare ("INSERT INTO codes (code,dt) VALUES ('$generator','$data_atual')");
$query -> execute();
  • Friend, got here anyway thanks!! I used date('Y-m-d h:i:s');, date =NOW() and in BD I put as timestamp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.