Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  59] [ 4]  / answers: 1 / hits: 52191  / 11 Years ago, fri, august 2, 2013, 12:00:00

I want save in my Datetime field the Date
For insert i haven't problem...
I have tried many attempts, this is the last but the result is the same



Insert:



var now = new Date();
var jsonDate = now.toJSON();
var then = new Date(jsonDate);


var o_voto_foto = {
profilo_id: profilo,
foto_id: data.id_foto_votata,
punteggio: data.voto,
proprietario_id: data.proprietario_foto,
created: then
};


connection.query('INSERT INTO prof_voto_foto SET ?', o_voto_foto, function(error, rows) {
if (error) {
var err = Error on INSERT 'votoFotoFancybox': + error;
console.error(err);
throw err;
}


Update table:



var now = new Date();
var jsonDate = now.toJSON();
var then = new Date(jsonDate);

connection.query('UPDATE prof_voto_foto SET punteggio = ' + data.voto + ', created = ' + then +' WHERE profilo_id = ' + profilo + ' AND foto_id = ' + data.id_foto_votata, function(error, rows) {
if (error) {
var err = Error on UPDATE 'votoFotoFancybox': + error;
console.error(err);
throw err;
}


And i recive this error:



Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Aug 02 2013 19:03:13 GMT+0200 (CEST) WHERE profilo_id = 103 AND foto_id = 5' at line 1

More From » mysql

 Answers
11

With the help of @tadman, it's works



created = new Date();
connection.query('UPDATE prof_voto_foto SET punteggio = ' + connection.escape(data.voto) + ', created = ' + connection.escape(created) + ' WHERE profilo_id = ' + connection.escape(profilo) + ' AND foto_id = ' + connection.escape(data.id_foto_votata), function(error, rows) {

[#76557] Thursday, August 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
naya

Total Points: 60
Total Questions: 87
Total Answers: 87

Location: Guam
Member since Fri, Jun 18, 2021
3 Years ago
;