开发者

Mysql_fetch_assoc(): supplied argument is not a valid MySQL result … [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

I tried every开发者_运维知识库thing I could think of, but I keep on getting this error.

Mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /url/ on line 41

if ( $_POST[submit] == "Submit" )
    {
        $sql="INSERT INTO table (`content`, `userid`, `ttime`) VALUES 
('$_POST[content]', '".$user_id."', '".time()."')";
    $res = mysql_query($sql,$link) or die(mysql_error());
/* (line 41 is the following)*/ 
while($result = mysql_fetch_assoc($res)) {
    } }

I tried printing out the error (no error prints out just the warning), I tried changing the query, everything I could think of. The code works just fine - it does the insert on click, everything is fine, just that warning is appearing ._.'

Any ideas?


From php documentation on mysql_query()

Return Values

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.


You can't fetch a result from an INSERT query.


You are attempting to obtain a data row from a query that is not a SELECT query. You can only fetch associated arrays from a result data set. An INSERT query just does its thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜