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 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'