2013-05-01 78 views
0

這是我的代碼。我沒有收到錯誤聲明,但數據未插入到表中。我試着在PHPMyAdmin中運行查詢,它工作正常。這也不是因爲用戶權限。SQL插入聲明掛起

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')"; 

這是代碼弄亂行......它只是掛起,永不打印出die消息

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

它從來沒有打印出這一行。

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

不存儲在數據庫中的文件內容(除非有一個真正的好理由) – 2013-05-01 03:58:01

+0

是否有你'從切換的原因$ mysql'到'$ mysqli'在失敗的行中? – Ding 2013-05-01 04:23:12

回答

2

您與$mysql物體在頂部工作,突然,你觸發$mysqli對象查詢。

變化

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

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

不錯的答案:)... – Ding 2013-05-01 04:48:09

+0

謝謝!!你幫我在班上得到了A – codinggurl 2013-07-01 20:45:05