I know this may be easier than it sounds, but ive been searching online for a solution for hours. I want to add a simple html text box to a form where the user can input "arrival time" and submit to mysql. Thanks in advance.
1条回答 默认 最新
- dongwen3410 2013-02-05 18:37关注
Have the text box validated to a known form, example:
2007-06-05 15:26:0
parse that submitted and validated value to a PHP date object using strtotime() like so:
$timestamp = strtotime($_POST['userinput']); $mysql_date = date("Y-m-d H:m:s", $timestamp);
Documentation for strtotime: http://php.net/manual/en/function.strtotime.php
Then just put the $mysql_date variable into the DB in a datetime column.
Edit: add code for how to validate a value to mysql time string
function TimeIsValid(){ var field = document.getElementById('timeid'); if(field.value.match("/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/")) return true; }
I'm not sure how good that regex is, I didn't write it, grabbed it from: http://www.dzone.com/snippets/regular-expression-match
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
- ¥15 怎么生成确定数目的泊松点过程
- ¥15 layui数据表格多次重载的数据覆盖问题
- ¥15 python点云生成mesh精度不够怎么办
- ¥15 QT C++ 鼠标键盘通信
- ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
- ¥50 高维数据处理方法求指导
- ¥100 数字取证课程 关于FAT文件系统的操作
- ¥15 如何使用js实现打印时每页设置统一的标题
- ¥15 安装TIA PortalV15.1报错