使用PHP将$ date变量存储到mysql数据库中 [英] Storing the $date variable into mysql database using php

查看:136
本文介绍了使用PHP将$ date变量存储到mysql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将$ date变量存储在称为数据类型varchar(50)

I have a problem in storing the $date variable in the database column called data of type varchar(50)

这是日期变量的代码

$date = date("Y-m-d");
echo $date;

这是将其存储到数据库中的代码(请注意日期是相同的)

and this is the code that stores it into the database (notice that the date is the same one)

我的代码有什么问题

 $sql="INSERT INTO 
    Students(FirstName, LastName,gender,Major,Favorite_courses,GPA,date)
 VALUES 
    ('$_POST[firstname]','$_POST[lastname]','$_POST[sex]','$_POST[major]',
     '$_POST[favorite]','$_POST[GPA]','$date')";

推荐答案

将列类型更改为DATE,然后使用SYSDATE作为值在SQL Server上输入当前日期/时间.

Change the column type to DATE and then use SYSDATE as the value to input the current date/time on the SQL server.

另外,请阅读SQL注入!

Also, read up on SQL injection!

这篇关于使用PHP将$ date变量存储到mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆