Visualizzazione dei risultati da 1 a 7 su 7

Discussione: time() e timestamp

  1. #1

    time() e timestamp

    perche se inserisco del time in un campo database timestamp non lo mette?

    Codice PHP:
    $data=time()
    mysql_query("INSERT INTO tabella (data) values ('$time')"); 
    mi da sempre 0000-00-00 00:00:00

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,448
    Perché la variabile l'hai chiamata $data, non $time

  3. #3
    no scusa è stato un errore mio di battitura:

    Codice PHP:
    $data=time() 
    mysql_query("INSERT INTO tabella (data) values ('$data')"); 
    e da quel problema.

  4. #4
    ecco vi posto il code completo:

    Codice PHP:
    $datainvio=time();
        
    $sql="INSERT INTO boxmessage (IDMsg, IDUtenteSent, IDUtenteReciver, Oggetto, Messaggio, Stato, DataInvio) values ";
        
    $sql.="('$idmsg', '$_COOKIE[IDUtente_Network]', '$idutentereciver', '$object', '$message', '0', '$datainvio')";
        
    mysql_query($sql); 

  5. #5
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,448
    time() restituisce un timestamp in stile UNIX, ovvero un intero che rappresenta il numero di secondi dal 1/1/1970, quindi non è in formato aaaa-mm-dd hh:mm:ss

    fa così e vedi che dovrebbe andare
    $datainvio = date('Y-m-d H:i:s',time());

  6. #6
    un ultima cosa è possibile aggiungere un elemento ad un array e metterlo in prima posizione?

  7. #7
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,448
    Codice PHP:
    $elemento_da_inserire = array($elemento);
    $array_esistente array_merge($elemento_da_inserire,$array_esistente); 

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.