看板 PHP 關於我們 聯絡資訊
我有一個上傳圖片的網址 在上傳完圖片後 我寫成可以顯示出 圖片所在的路徑 但是我要怎麼寫才可以把它寫進我的資料庫中 EX: 圖片上傳完的路徑是 "./upload_files/class.JPG" 要怎麼將這一串字串寫進資料庫中 (部分code) 資料庫 member 資料表 users 存放圖片路徑的欄位 photo $photo_url = $upload_dir.$_FILES["myfile"]["name"]; echo "目前檔案的路徑 : " . $photo_url; //怎麼將這行寫進我資料庫?? $link = mysql_connect("localhost", "xxxx", "xxxx"); if (!$link) die("建立資料連接失敗"); $db_selected = mysql_select_db("member", $link); if (!$db_selected) die("開啟資料庫失敗"); mysql_free_result($result); $sql = "INSERT INTO users (photo) VALUES ('$photo')"; $result = mysql_query($sql, $link); if (!$result) die("執行 SQL 命令失敗"); -- 看著遠方香草天空想妳的笑容 走在熱鬧的午後街道品嚐著寂寞 ∮CoMix -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.173.73.149
chph :你都能寫出 INSERT INTO .. 怎麼還會問這問題? 11/18 23:50
lindoyle :你的問題是Insert這個部份失敗嗎? 11/19 00:03
CoMix :嗯嗯 對阿 我覺得很奇怪 為什麼會失敗 ... 11/19 00:39
PHP5 :前面是 $photo_url ,後面 $photo ?? 11/19 00:43
cttlee :echo $sql 你就知道了 11/19 01:47