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
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.

Link to comment
Share on other sites

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..

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.