Re: [SQL ] UPDATE 成功,但是還是有錯誤訊息

看板Database作者 (-858993460)時間12年前 (2011/12/16 21:44), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《dontkissme (不要親我)》之銘言: : 我在PHP下了一道語法 : 一邊開資料庫看資料確實有備修改,但是,總會出現以下錯誤訊息 : Warning: mysql_num_rows(): supplied argument is not a valid MySQL : result resource in 檔案夾/mng_profile2.php on line 101 : 檔案夾是我省略路徑,因為太長了。 : 很奇怪,資料都能改,但是一定會出現這個錯誤訊息。 : 我的$sql是以下這段 : UPDATE member SET user_name='小明',user_organization='小六', : user_phone='0222222222',user_mail='信箱',user_password='密碼' : WHERE user_account = '小明的帳號' : 用以下語法執行 : mysql_query("SET NAMES 'utf8'"); : $result=mysql_query($sql,$link); : if(!$result) die("SQL無法執行。"); : $check=mysql_num_rows($result); : echo 出來的 $check 是 0 筆,但是還是可以修改.... : 請高手幫我解答,如何成功修改又不會有錯誤訊息。 : 以前都這樣寫的阿。 : 感謝 因為你搞錯了 mysql_query 的回傳值了 http://tw.php.net/mysql_query 它只有在有回傳資料集時才是回傳一個 resource 才能餵進 mysql_num_rows() 如果是像 INSERT, UPDATE, DELETE, DROP 等這種不用回傳資料集的 query 時 它的回傳值就是 true/false 因此不能餵進 mysql_num_rows() 要知道有幾列被影響了請使用 mysql_affected_rows() -- 'You've sort of made up for it tonight,' said Harry. 'Getting the sword. Finishing the Horcrux. Saving my life.' 'That makes me sound a lot cooler then I was,' Ron mumbled. 'Stuff like that always sounds cooler then it really was,' said Harry. 'I've been trying to tell you that for years.' -- Harry Potter and the Deathly Hollows, P.308 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.28.91

12/16 22:00, , 1F
我剛剛直接道後台丟SQL有慢慢發現這個
12/16 22:00, 1F

12/16 22:00, , 2F
非常感謝,我現在來改
12/16 22:00, 2F
文章代碼(AID): #1EwqjEFL (Database)
文章代碼(AID): #1EwqjEFL (Database)