1

Why do I have a sytax error on line 21? (at the if($sql) line) I am new to this and cannot figure it out. I have been spinning my wheels for an hour. I'm sure its something very simple for most people on here.

 <?php 
    $conn = mysql_connect("localhost","root","") or die(mysql_error());
    mysql_select_db("solera_menu",$conn);

    if(isset($_POST['submit']))
    {
        $file = $_FILES['file']['tmp_name'];

        $handle = fopen($file,"r");
        while(($fileop = fgetcsv($handle,1000,",")) !==false)
        {
            $order = $fileop[0];
            $category = $fileop[1];
            $name = $fileop[2];
            $description = $fileop[3];
            $price = $fileop[4];


            $sql = mysql_query("INSERT INTO dinner (order,category,name,description,price) VALUES ('$order','$category','$name','$description','$price')")

            if($sql)
            {
                echo 'Data Uploaded Successfully';
            }
        }

    }

?>
4

1 回答 1

4

后面没有分号mysql_query()

如果您只是导入 CSV 文件,请尝试该LOAD DATA LOCAL INFILE语句或其命令行界面mysqlimport

这可能比您使用的方法快 10-20 倍。

它还可以防止您使用当前代码创建的 SQL 注入漏洞。

这是一个粗略的例子,虽然我没有测试过:

<?php 
    $conn = mysql_connect("localhost","root","") or die(mysql_error());
    mysql_select_db("solera_menu",$conn);

    if(isset($_POST['submit']))
    {
        $file = $_FILES['file']['tmp_name'];
        $status = mysql_query("LOAD DATA LOCAL INFILE '$file' INTO TABLE dinner");

        if($status)
        {
            echo 'Data Uploaded Successfully';
        }
    }
?>
于 2013-05-03T21:57:33.267 回答