SQL插入语句挂起

时间:2013-05-01 03:56:44

标签: php mysql database mysqli

这是我的代码。我没有收到错误声明,但数据未插入表中。我尝试在PHPMyAdmin中运行查询,它运行正常。这也不是因为用户权限。

  if ($mysql->connect_errno) {
        echo("Connect failed: ". $mysql->connect_error);
        die();
    }
    echo "I am confused by this thing<br>";

    if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
    {
        echo "Trying to figure out the errors!!!!<br>";
        $fileName = $mysql->real_escape_string($_FILES['userfile']['name']);
        $tmpName  = $mysql->real_escape_string($_FILES['userfile']['tmp_name']);
        $fileSize = intval($_FILES['userfile']['size']);
        $fileType = $mysql->real_escape_string($_FILES['userfile']['type']);
        echo $fileName."<br>";
        echo $tmpName."<br>";
        echo $fileSize."<br>";
        echo $fileType."<br>";
        //reads the file information
        $fp      = fopen($tmpName, 'r');
        $content = fread($fp, filesize($tmpName));
        $content = $mysql->real_escape_string(addslashes($content));
        fclose($fp);
        //this just adds slashes

这会添加斜杠

        if(!get_magic_quotes_gpc())
        {
            $fileName = addslashes($fileName);
        }

        //This inserts into the databse
        $query = "INSERT INTO upload VALUES ('', '$fileName', '$fileType', $fileSize, '$content')";

这是代码混乱的行......它只是挂起并且永远不会打印出来的消息

        $updateDB = $mysqli->query($query) or die($mysqli->error);

它永远不会打印出这一行。

        echo "<br>File $fileName uploaded<br>";
    } 

1 个答案:

答案 0 :(得分:2)

您正在使用$mysql对象在顶部突然,您在$mysqli对象上触发了您的查询。

更改

$updateDB = $mysqli->query($query) or die($mysqli->error);

$updateDB = $mysql->query($query) or die($mysql->error);