Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SQL插入日期始终为空_Php_Mysql_Sql_Csv - Fatal编程技术网

Php SQL插入日期始终为空

Php SQL插入日期始终为空,php,mysql,sql,csv,Php,Mysql,Sql,Csv,我正在尝试使用上载页面插入数据库,代码如下: if($file!=="") { echo "<br/>".$file; $handle = fopen($file, "r"); $row = 0; $delete_records = mysql_query("DELETE FROM affiliationagreements"); $delete_records = mysql_query("

我正在尝试使用上载页面插入数据库,代码如下:

if($file!=="")
    {

        echo "<br/>".$file;
        $handle = fopen($file, "r");
        $row = 0;

        $delete_records = mysql_query("DELETE FROM affiliationagreements");
        $delete_records = mysql_query("DELETE FROM college");
        $delete_records = mysql_query("DELETE FROM program");
        $delete_records = mysql_query("DELETE FROM facility");
        $delete_records = mysql_query("DELETE FROM submitor");
        $delete_records = mysql_query("DELETE FROM location");
        //will loop each record in the CSV file
        while(($fileop = fgetcsv($handle,1000,",")) !== false )
        {
            //columns names of the CSV file are not needed
            if($row==0)
            {
                $row++;
            }
            else
                {
                    //accept apostrophes in the strings
                    $fileop = array_map("mysql_real_escape_string",$fileop);

                    $sql = mysql_query("INSERT INTO affiliationagreements(id, AANumber, Facility, Submitor, Program, Location, College, SubmissionDate, Action, EffectiveDate, Status, ExpirationDate)
                                    VALUES('',
                                    '$fileop[0]', 
                                    '$fileop[1]', 
                                    '$fileop[2]', 
                                    '$fileop[3]', 
                                    '$fileop[4]', 
                                    '$fileop[5]', 
                                    '$fileop[11]', 
                                    '$fileop[23]', 
                                    '$fileop[24]', 
                                    '$fileop[25]', 
                                    '$fileop[26]') 
                                ")or die(mysql_error());
如果我将SubmissionDate、EffectiveDate和ExpirationDate更改为varchar,它们将正确插入,但我无法使用varchar,因为我正在比较日期值。还有建议


***更新。在CSV文件中,格式为MM/DD/YYYY。我不认为这会是个问题。改变这个会更好吗?我删除记录是因为我的老板希望在重新上传文件之前清除数据库,因为上传的文件是之前上传的文件的更新****

检查日期格式,因为它需要是YYYY-MM-DD格式

INSERT INTO table SET date = '2014-05-13'

如果格式不同,则日期将改为存储“0000-00-00”。因此,在运行查询之前,通过回显查询字符串来仔细检查插入情况。

mysql
date
字段仅接受以下格式的日期:
0000-00-00

您可以在insert查询中使用
DATE\u FORMAT()
,但我不能给出示例,因为您没有公布实际日期的格式


旁注:您确实意识到您一直在用
$delete\u records=mysql\u query
覆盖您的查询,另外,您没有
WHERE
子句,那么如何知道删除什么呢?@Fred ii-这是故意的,因为它是一个测试脚本。此外,由于性能原因,不建议使用NULL。您是否尝试回显您的查询?您将不得不发布一些有效负载数据。当你猜不到你要插入的实际值时,很好。如果这是问题所在,我不会感到惊讶。是的,就是这样。愚蠢的数据库简直是荒谬可笑。再次感谢
INSERT INTO table SET date = '2014-05-13'