麻煩幫小弟解決一下這個問題

來源:互聯網
上載者:User
小弟剛學php不久,寫了如下代碼,各位大俠見笑了。
代碼的大概功能是在當前頁面修改頁面上顯示的圖片和文字。文字資訊和圖片資訊儲存在mySQL相應的表格裡。
Item Detail
 
Edit item:
The file is not an image.

';}else{mysql_query("LOCK TABLES IMAGES WRITE");mysql_query("LOCK TABLES ITEM WRITE");if($img_id == 1){mysql_query("INSERT INTO IMAGES (IMG_NAME, IMG) VALUES ('$image_name', '$image')");$pic_id = mysql_insert_id();mysql_query("UPDATE ITEM SET IMG_ID = $pic_id WHERE ITEM_ID = $item_id");}else{mysql_query("UPDATE IMAGES SET IMG_NAME = '$image_name', IMG = '$image' WHERE IMG_ID = $img_id");}mysql_query("UNLOCK TABLES");header("location: " . $_SERVER['REQUEST_URI']);}}}}if(isset($_POST['sub_del_pic'])){mysql_query("LOCK TABLES ITEM WRITE");mysql_query("UPDATE ITEM SET IMG_ID = 1WHERE ITEM_ID = $item_id");if($img_id != 1){mysql_query("LOCK TABLES IMAGES WRITE");mysql_query("DELETE FROM IMAGES WHERE IMG_ID = $img_id");}mysql_query("UNLOCK TABLES");header("location: " . $_SERVER['REQUEST_URI']);}?>
Congratulations! The item is yours.

';}else{print'

Sorry, the item has been sold!

';}}else if($status == "NA"){print'

Item is not available yet!

';}else if($status == "EXPIRE"){print'

Item is expired.

';}else{date_default_timezone_set('America/New_York');$curr_date = date("Y-m-d");$curr_time = date("H:i");$curr_datetime = "$curr_date $curr_time:00";print"

Current datetime: $curr_datetime

";$result = mysql_query("SELECT * FROM ITEM WHERE ITEM_ID = $item_id");if($result){$row = mysql_fetch_array($result);$btime = strtotime($row['BEGIN']);$etime = strtotime($row['END']);$date = date("Y-m-d", $etime);$time = date("H:i", $etime);}print'
';if($_POST['go'] == "Set Time"){$end_date = $_POST['end_date'];$end_time = $_POST['end_time'];$end_time = $end_time.':00';$end_datetime = strtotime("$end_date $end_time");$now = strtotime($default_datetime);$problem = false;if ($end_datetime <= $now){print'You cannot set End time earlier than current time!';$problem = true;}if(!$problem){mysql_query("LOCK TABLES ITEM WRITE");mysql_query("UPDATE ITEM SET END = '$end_date $end_time' WHERE ITEM_ID = $item_id");mysql_query("UNLOCK TABLES");header("location: " . $_SERVER['REQUEST_URI']);}}refresh();}?>
Buy it Now Price:

問題:第 120行的插入命令為什麼不能執行?什麼原因導致?怎麼解決?


回複討論(解決方案)

自己多echo輸出下看看,查看mysql_query()的傳回值是啥?

mysql_query("INSERT INTO IMAGES (IMG_NAME, IMG) VALUES ('$image_name', '$image')");

$image = addslashes(file_get_contents($file));

$file 顯然是二進位檔案
那麼僅僅 addslashes 對於 mysql 5 是不行的(mysql 4 可以)
因為大多不可列印的 ASCII 字元都會影響 mysql 的行為

如果一定要將圖片資料存放於資料庫中,那麼要存放圖片資料的 base64 編碼

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.