
Originariamente inviata da
camionistaxcaso
Ma tipo postare il codice PHP?

E' lo stesso che ha postato alkatraz, quindi...
Comunque per completezza:
Codice PHP:
// $id contiene l'identificazione dell'utente.
// I dati passati al database arrivano via ajax e sono presi così:
$nickname = filter_input( INPUT_POST, 'nickname', FILTER_CALLBACK, array( 'options' => 'verificaStringa' ));
$room = filter_input( INPUT_POST, 'stanza', FILTER_CALLBACK, array( 'options' => 'verificaStringa' ));
$stringa = utf8_decode( filter_input( INPUT_POST, 'stringa', FILTER_CALLBACK, array( 'options' => 'verificaStringa' )));
$colore = filter_input( INPUT_POST, 'colore', FILTER_CALLBACK, array( 'options' => 'verificaStringa' ));
$background = filter_input( INPUT_POST, 'background', FILTER_CALLBACK, array( 'options' => 'verificaStringa' ));
// Connette al database, è una funzione remota in un altro file.
$conn = PDOConnetti();
if ( $id ){
// Inserisce i dati nel database
$handle->closeCursor();
$sql = 'INSERT INTO chat ( id_ute, stanza, frase, data_inserimento, colore, background )';
$sql .= 'VALUES ( :id, :room, :frase, CURDATE(), :col, :bkg );';
$handle = $conn->prepare( $sql );
$handle->bindValue( ':id', (int)$id['id_ute'], PDO::PARAM_INT );
if ( $room === false || $room == '') $room = 'generale';
$handle->bindValue( ':room', $room, PDO::PARAM_STR );
$handle->bindValue( ':frase', $stringa, PDO::PARAM_STR );
if ( $colore === false || $colore == '') $colore = 'bianco';
$handle->bindValue( ':col', $colore, PDO::PARAM_STR );
if ( $background === false || $background == '') $background = 'bg-bianco';
$handle->bindValue( ':bkg', $background, PDO::PARAM_STR );
$handle->execute();
}
// Presegue...
L'unica differenza è stata che invece di usare CURRENT_TIMESTAMP ho usato CURDATE ed è stato l'errore, dato che CURDATE riporta solo la data, a volte funzionava e a volte no ( e questo è indubbiamente strano e mi ha indotto in errore )
Ora dato che CURRENT_TIMESTAMP è una funzione alias di NOW ho usato quest'ultima e sembra che stia funzionando.
Quindi la query è divenuta:
Codice PHP:
$sql = 'INSERT INTO chat ( id_ute, stanza, frase, data_inserimento, colore, background )';
$sql .= 'VALUES ( :id, :room, :frase, NOW(), :col, :bkg );';