Sql calculates date instead of insert

-1

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

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

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

?>
    
asked by anonymous 13.07.2017 / 02:40

1 answer

0

Missing parentheses in sql. You do not need to use periods in the variables: if you use single quotes in variables, then use double quotation marks in the SQL row. PDO has to prepare before running.

$query = $conn -> prepare ("INSERT INTO codes (code,dt) VALUES ('$generator','$data_atual')");
$query -> execute();
    
13.07.2017 / 03:58