dsxon40042 2013-05-01 03:56
浏览 22
已采纳

SQL插入语句挂起

Here is my code. I am not getting an error statement, but the data is not inserted into the table. I tried running the query in PHPMyAdmin and it worked fine. It is also not because of user privileges.

  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

This adds slashes

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

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

This is the line where the code messes up... It just hangs and never prints out the die message

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

It never prints out this line.

        echo "<br>File $fileName uploaded<br>";
    } 
  • 写回答

1条回答 默认 最新

  • douchen7324 2013-05-01 04:20
    关注

    You are working with $mysql object on the top and abruptly, you triggered your query on $mysqli object.

    Change

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

    to

    $updateDB = $mysql->query($query) or die($mysql->error);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真