Jump to content

[SOLVED] inserting date & time


jonathanbee

Recommended Posts

I've been trying to get this working forever and searching though these forums.. please help.

 

I am using now(), but I'd like to use strftime("%d. %B %Y %R"). I can't for the life of me figure out how to use strftime("%d. %B %Y %R") in the code below without it failing.

 

The other issue is that both now() and strftime("%d. %B %Y %R") return 9/27 as the date. But it's 9/28.  How can get it to return the correct date? I thought the setlocale would address this.

 

 

<?php

 

@setlocale(LC_TIME, 'ja_JP.EUC-JP');

mb_language('Japanese');

mb_internal_encoding("EUC-JP");

mb_http_output("EUC-JP");

 

$query = "Insert into res (name,gender,age,country,other_country,first_time,email,f1n,f1e,f2n,f2e,comments,t_stamp) values ('$_POST[name]','$_POST[gender]','$_POST[age]','$_POST[country]','$_POST[other_country]','$_POST[first_time]','$_POST','$_POST[f1n]','$_POST[f1e]','$_POST[f2n]','$_POST[f2e]','$_POST[comments]',now())";

$result = mysql_query($query) or die("Insert failed");

?>

 

Link to comment
https://forums.phpfreaks.com/topic/71000-solved-inserting-date-time/
Share on other sites

<?php

@setlocale(LC_TIME, 'ja_JP.EUC-JP');
mb_language('Japanese');
mb_internal_encoding("EUC-JP");
mb_http_output("EUC-JP");

$query = "
  INSERT INTO res (
    name,
    gender,
    age,
    country,
    other_country,
    first_time,
    email,
    f1n,
    f1e,
    f2n,
    f2e,
    comments,
    t_stamp
   ) VALUES (
    '{$_POST['name']}',
    '{$_POST['gender']}',
    '{$_POST['age']}',
    '{$_POST['country']}',
    '{$_POST['other_country']}',
    '{$_POST['first_time']}',
    '{$_POST['email']}',
    '{$_POST['f1n']}',
    '{$_POST['f1e']}',
    '{$_POST['f2n']}',
    '{$_POST['f2e']}',
    '{$_POST['comments']}',
    " . strftime("%d. %B %Y %R") . "
  )";

$result = mysql_query($query) or die("Insert failed");

?>

 

ps: Placing post vars directly in your query like that (without any escaping) is a huge security whole.

Alright, I finally got it working and even managed to get the correct time for this time zone.  Now if I could just get the data into the db,    it will echo the $f_time to screen, but in the db.. it's empty..

 

function jtime() {

    $b = time () + 57600;

    $fixed_time = date("D, F jS G:i a",$b);

    return $fixed_time;

    }

 

$f_time = jtime();

 

$query = "Insert into res (name,gender,age,country,other_country,first_time,email,f1n,f1e,f2n,f2e,comments,t_stamp) values ('$_POST[name]','$_POST[gender]','$_POST[age]','$_POST[country]','$_POST[other_country]','$_POST[first_time]','$_POST','$_POST[f1n]','$_POST[f1e]','$_POST[f2n]','$_POST[f2e]','$_POST[comments]', '$_POST[f_time]')";

 

Please help..

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.