【问题标题】:Date Select boxs values convert to SQL data base date type value日期选择框值转换为 SQL 数据库日期类型值
【发布时间】:2017-06-30 07:24:14
【问题描述】:

我的网站有三个选择框,分别是年、月和日。那些选择框的值是这样的。

  • 年份框值 - 1992
  • 蛾盒价值 - 02
  • 日期框值 - 05

我想转换为将我的 SQL 数据库存储在日期类型列中。

首先我绑定直接给SQL数据库的INSERT。它也不起作用。

$year . '-' . $month . '-' . $date

我试图通过下面的代码来修道院,但它得到了错误。

$birthdate = Convert(varchar(30),$year . '-' . $month . '-' . $date,102);

错误:

警告:main():依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种,但仍然收到此警告,您很可能拼错了时区标识符。我们现在选择时区“UTC”,但请设置 date.timezone 以选择您的时区。

致命错误:调用未定义函数 Convert()

PHP 代码:

$birthdate = $d9 .'-' . $d10 . '-'. $d11;

$sql = "INSERT INTO users (you, usernames, usernamee, initials, firstname, midname, lastname, gender, birth_date, email, password, nic, phone, district, country, ip, signup, lastlogin, notescheck) 
            VALUES('$d1','$d2','$d3','$d4','$d5','$d6','$d7','$d8',$birthdate,'$d12','$p_hash','$d15','$d16','$d17','USA', '$ip',now(),now(),now())";

【问题讨论】:

标签: php mysql sql-server date datetime


【解决方案1】:

只需附加字符串:

$birthdate = $year.'-'.$month.'-'.$date;

$sql = "INSERT INTO users (you, usernames, usernamee, initials, firstname, midname, lastname, gender, birth_date, email, password, nic, phone, district, country, ip, signup, lastlogin, notescheck) 
            VALUES('$d1','$d2','$d3','$d4','$d5','$d6','$d7','$d8','$birthdate','$d12','$p_hash','$d15','$d16','$d17','USA', '$ip',now(),now(),now())";

【讨论】:

  • 我没有收到任何错误,但该值不会插入数据库。其他值通常插入到数据库中。
  • 我放在上面了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-15
  • 1970-01-01
  • 1970-01-01
  • 2021-04-10
  • 2013-08-16
相关资源
最近更新 更多