jonathanbee Posted September 28, 2007 Share Posted September 28, 2007 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/71000-solved-inserting-date-time/ Share on other sites More sharing options...
trq Posted September 28, 2007 Share Posted September 28, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/71000-solved-inserting-date-time/#findComment-356992 Share on other sites More sharing options...
jonathanbee Posted September 28, 2007 Author Share Posted September 28, 2007 Thanks for reply and advice. I will check that out. I did insert the code your posted, but it failed, I will play around with it. Any more advice would be very appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/71000-solved-inserting-date-time/#findComment-356997 Share on other sites More sharing options...
jonathanbee Posted September 28, 2007 Author Share Posted September 28, 2007 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.. Quote Link to comment https://forums.phpfreaks.com/topic/71000-solved-inserting-date-time/#findComment-357012 Share on other sites More sharing options...
jonathanbee Posted September 28, 2007 Author Share Posted September 28, 2007 found the mistake, should have been '$f_time' Quote Link to comment https://forums.phpfreaks.com/topic/71000-solved-inserting-date-time/#findComment-357023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.