2011-08-14 83 views
0

當我嘗試運行此:MySQL的受影響的行 - 幫助

$s=mysql_query("INSERT INTO forum_topics (forum_id,userid,title,createtime,createip,last_post_user,last_post_userid,last_post_time) VALUES ('$forum_cat_id','$userid','$title','$time','$ip','{$userdata['username']}','$userid','$time')"); 
     if(mysql_affected_rows($s) == 0) 
      return 7; 

我得到以下錯誤:警告:

mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in "PATH/TO/FILE" on line 76 

這是爲什麼?

編輯:(我做的var_dump後,返回此):

bool(true) string(0) "" Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in "PATH/TO/SITE" on line 77 
+0

'的var_dump($ S); var_dump(mysql_error());'---把它放在你的'$ s = ...'行後 – zerkms

+0

更新我的問題。 –

+0

http://www.php.net/manual/en/function.mysql-affected-rows.php – zerkms

回答

4

你並不需要通過$smysql_affected_rows()功能

+0

然後它返回這個錯誤: 注意:使用未定義的常量mysql_affected_rows - 假定'mysql_affected_rows'在 –

+0

更新:對不起,我錯了。那就是訣竅。謝謝! –

0

這是一個很常見的錯誤。最常見的問題是,您的查詢是錯誤的。

Example: No of Columns do not match, a field requires '' around it and you are omitting that, you are insert wrong type of data into a field.

爲了更好地排查,從PHP代碼使用mysql_error()函數吐出錯誤。

若要更多地拍攝它,請將查詢分配給變量$ query並打印出該查詢。在MySQL中運行,看看你得到了什麼錯誤。

1

嘗試沒有paassing沒什麼mysq_affected_rows()

$s=mysql_query("INSERT INTO forum_topics (forum_id,userid,title,createtime,createip,last_post_user,last_post_userid,last_post_time) VALUES ('$forum_cat_id','$userid','$title','$time','$ip','{$userdata['username']}','$userid','$time')"); 
     if(mysql_affected_rows() == 0) 

    return 7; 
+0

感謝兄弟幫助我很多.. –