shebbycs Posted April 1, 2013 Share Posted April 1, 2013 <?php session_start(); if (empty($_SESSION['is_logged_in'])) { header("Location:login.php"); die(); // just to make sure no scripts execute } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Counter Cash OK Form</title> <script type="text/javascript"> function a() { var a = document.form.cname.value; var b = document.form.camount.value; var c = document.form.cshortage.value; var d = document.form.cexcess.value; var e = document.form.pamount.value; var f = document.form.pshortage.value; var g = document.form.premark.value; var h = document.form.hname.value; var i = document.form.csign.value; var j = document.form.hsign.value; if(a==""&& b==""&& c==""&& d==""&& e==""&& f==""&& g==""&& h=="") { alert("Please Insert All Data"); return false; } if(a=="") { alert("Please Insert Cashier Name"); return false; } if(b=="") { alert("Please Insert Counter Cash(Amount)"); return false; } if(c=="") { alert("Please Insert Counter Cash(Shortage)"); return false; } if(d=="") { alert("Please Insert Counter Cash(Excess)"); return false; } if(e=="") { alert("Please Insert Petty Cash(Amount)"); return false; } if(f=="") { alert("Please Insert Petty Cash(Shortage)"); return false; } if(g=="") { alert("Please Insert Petty Cash(Remark)"); return false; } if(h=="") { alert("Please Insert Handover Name"); return false; } } </script> </head> <body> <form name="form" method="post" action="countercash.php" onsubmit="return a()"> <center>COUNTER CASH FORM<br><br></center> <table border=0 align=center> <tr align="center"> <td>CASHIER NAME</td> <td>:</td> <td><input type=text name="cname"></td> </tr> <tr></tr><tr></tr><tr></tr><tr></tr><tr></tr> <tr> <td colspan="3" align="center">COUNTER CASH</td> </tr> <tr></tr><tr></tr> <tr align="center"> <td>AMOUNT</td> <td>:</td> <td>RM<input type=text name="camount"></td> </tr> <tr align="center"> <td>SHORTAGE</td> <td>:</td> <td>RM<input type=text name="cshortage"></td> </tr> <tr align="center"> <td>EXCESS</td> <td>:</td> <td>RM<input type=text name="cexcess"></td> </tr> <tr></tr><tr></tr><tr></tr><tr></tr><tr></tr> <tr> <td colspan="3" align="center">PETTY CASH</td> </tr> <tr></tr><tr></tr> <tr align="center"> <td>AMOUNT</td> <td>:</td> <td>RM<input type=text name="pamount"></td> </tr> <tr align="center"> <td>SHORTAGE</td> <td>:</td> <td>RM<input type=text name="pshortage"></td> </tr> <tr align="center"> <td>REMARK</td> <td>:</td> <td><textarea name="premark"></textarea></td> </tr> <tr></tr><tr></tr><tr></tr><tr></tr><tr></tr> <tr align="center"> <td>SIGN</td> <td>:</td> <td><input type=text name="csign"></td> </tr> <tr align="center"> <td>HANDOVER TO (NAME)</td> <td>:</td> <td><input type=text name="hname"></td> </tr> <tr align="center"> <td>SIGN</td> <td>:</td> <td><input type=text name="hsign"></td> </tr> <tr></tr><tr></tr><tr></tr><tr></tr> <input type="hidden" name="thisID"> <input type="hidden" name="date" value="<?php date_default_timezone_set('Asia/Kuala_Lumpur'); echo date('d-m-Y H:i:s');?>" /> <tr> <td colspan="3" align="center"><input type=submit name="submit" value="Submit"></td> </tr> </form> </body> </html> The coding was right and it update the datetime in database but the mistake was its not update time according when the moment user click submit button but instead when the form is appear, time was saved and put as default Any suggestion please Link to comment https://forums.phpfreaks.com/topic/276384-how-to-make-the-default-datetime-especially-time-is-updated-according-when-user-click-submit-button/ Share on other sites More sharing options...
Psycho Posted April 1, 2013 Share Posted April 1, 2013 What? Your question is in the PHP forum, but there really isn't any PHP code in what you posted above, aside from the redirect. And, you haven't specified what "datetime" you are talking about. Link to comment https://forums.phpfreaks.com/topic/276384-how-to-make-the-default-datetime-especially-time-is-updated-according-when-user-click-submit-button/#findComment-1422278 Share on other sites More sharing options...
Psycho Posted April 1, 2013 Share Posted April 1, 2013 Ok, after reading through your code I see this (which YOU should have pointed out instad of expecting us to do it for you) <input type="hidden" name="date" value="<?php date_default_timezone_set('Asia/Kuala_Lumpur'); echo date('d-m-Y H:i:s');?>" /> If you want to save a value in the database based upon when the form was submitted then don't put a hidden field in the form to store the time when the form was generated. You can simply: 1) Determine the time when the form was submitted in PHP code on the script that processes the form submission or 2) Use the database functionality to do it for you. #2 is definitely the way to go. If this is only for new record creation, then create your time field in the database as a timestamp and set the default value to CURRENT_TIMESTAMP. Then you don't even need to include a timestamp in the INSERT query - it will be saved automatically. If you need to update the value when records are edited you can also set the field to update the value automatically in the database. Link to comment https://forums.phpfreaks.com/topic/276384-how-to-make-the-default-datetime-especially-time-is-updated-according-when-user-click-submit-button/#findComment-1422279 Share on other sites More sharing options...
shebbycs Posted April 1, 2013 Author Share Posted April 1, 2013 What? Your question is in the PHP forum, but there really isn't any PHP code in what you posted above, aside from the redirect. And, you haven't specified what "datetime" you are talking about. extremely sorry my mistake Link to comment https://forums.phpfreaks.com/topic/276384-how-to-make-the-default-datetime-especially-time-is-updated-according-when-user-click-submit-button/#findComment-1422354 Share on other sites More sharing options...
shebbycs Posted April 1, 2013 Author Share Posted April 1, 2013 Ok, after reading through your code I see this (which YOU should have pointed out instad of expecting us to do it for you) <input type="hidden" name="date" value="<?php date_default_timezone_set('Asia/Kuala_Lumpur'); echo date('d-m-Y H:i:s');?>" /> If you want to save a value in the database based upon when the form was submitted then don't put a hidden field in the form to store the time when the form was generated. You can simply: 1) Determine the time when the form was submitted in PHP code on the script that processes the form submission or 2) Use the database functionality to do it for you. #2 is definitely the way to go. If this is only for new record creation, then create your time field in the database as a timestamp and set the default value to CURRENT_TIMESTAMP. Then you don't even need to include a timestamp in the INSERT query - it will be saved automatically. If you need to update the value when records are edited you can also set the field to update the value automatically in the database. May i know the second solution I need to separate date and time? because my mysql i created as field "Date" and the type was varchar(100) Link to comment https://forums.phpfreaks.com/topic/276384-how-to-make-the-default-datetime-especially-time-is-updated-according-when-user-click-submit-button/#findComment-1422355 Share on other sites More sharing options...
shebbycs Posted April 1, 2013 Author Share Posted April 1, 2013 Ok, after reading through your code I see this (which YOU should have pointed out instad of expecting us to do it for you) <input type="hidden" name="date" value="<?php date_default_timezone_set('Asia/Kuala_Lumpur'); echo date('d-m-Y H:i:s');?>" /> If you want to save a value in the database based upon when the form was submitted then don't put a hidden field in the form to store the time when the form was generated. You can simply: 1) Determine the time when the form was submitted in PHP code on the script that processes the form submission or 2) Use the database functionality to do it for you. #2 is definitely the way to go. If this is only for new record creation, then create your time field in the database as a timestamp and set the default value to CURRENT_TIMESTAMP. Then you don't even need to include a timestamp in the INSERT query - it will be saved automatically. If you need to update the value when records are edited you can also set the field to update the value automatically in the database. but if i used current_timestamp it would not update based on malaysia time is there any setting to change it I am using phpmyadmin Link to comment https://forums.phpfreaks.com/topic/276384-how-to-make-the-default-datetime-especially-time-is-updated-according-when-user-click-submit-button/#findComment-1422356 Share on other sites More sharing options...
Psycho Posted April 3, 2013 Share Posted April 3, 2013 May i know the second solution I need to separate date and time? because my mysql i created as field "Date" and the type was varchar(100) Then you need to change that field to be a timestamp or a datetime field type. varchar is for text data. but if i used current_timestamp it would not update based on malaysia time is there any setting to change it I am using phpmyadmin It would update based upon the time that the MySQL server is running on. Is the MySQL server not in Malaysia? If so, (assuming you don't have rights to change the default settings of the server) you have several options: 1) You can set the time as per the server's timezone and then change the value when you retrieve the value 2) You can set the timezone for the MySQL connection on each session 3) To make your application "global" you can do both of the above. Set the timezone of the MySQL connection to UTC and then output the values based upon the user's timezone. For now, I would suggest just doing #1. You can set the timezone for the session with MySQL using something like this: SET time_zone = 'America/Los_Angeles'; I assume you would want to execute that right after you make a connection to the MySQL server in your scripts. But, I've never used it before. EDIT: Look here for how the timezone can be specified http://stackoverflow.com/questions/9808160/mysql-time-zones Link to comment https://forums.phpfreaks.com/topic/276384-how-to-make-the-default-datetime-especially-time-is-updated-according-when-user-click-submit-button/#findComment-1422653 Share on other sites More sharing options...
shebbycs Posted April 6, 2013 Author Share Posted April 6, 2013 Thanks Psycho and I managed where that form i just put <input type="hidden" name="date" and the action post I simply put $date = $_POST['date']; date_default_timezone_set('Asia/Kuala_Lumpur'); $date = date('y-m-d G:i:s'); and most important I change date format from varchar to datetime Thanks alot to you Problem solve Link to comment https://forums.phpfreaks.com/topic/276384-how-to-make-the-default-datetime-especially-time-is-updated-according-when-user-click-submit-button/#findComment-1423233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.