|
Posted by Norman Peelman on 11/23/07 15:47
bruno_guedesav wrote:
> On 22 nov, 14:57, Knut Krueger <knut.krue...@usa.com> wrote:
>>> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
>>> result resource in /home/grad/ccomp/06/guedesav/public_html/PbBlog/inc/
>>> db.php on line 28
>>> (line 28 is "while($data = mysql_fetch_array($result,MYSQL_ASSOC))")
>>> and havingthis warning on the HTML output leads to be impossible to
>>> use header() to, for instance, go back to the post removal page. Is
>>> there any way to know prior to fetching if my result is of and INSERT/
>>> UPDATE/DELETE instead of a SELECT query?
Yes, you are the programmer, you should know what function you are
calling and what you expect back. Split this into two functions. One
that performs INSERTS, UPDATES, DELETES, and returns affected rows and
one that performs SELECTS and returns arrays of data. You'll be on the
road to better programming practices.
>> withour talking abut the SQL problem - see the other guys it should be
>> possible to prvent the error message with
>>
>> $data = @mysql_fetch_array($result,MYSQL_ASSOC))
>>
>> I do not know whether it is working with
>> mysql_fetch_array($result,MYSQL_ASSOC))
>> but it is working with @mysql_query and @mysql_num_rows
>
> Oh, yes, it worked, indeed. There's no problem for me to have a single
> entrance on the loop because of the first obligatory fetch as long as
> it goes away cleanly so I can use headers afterwards, so this thread
> is ended for me.
This is not the answer to your problem. There is no result set to
return on an INSERT, UPDATE, etc. But if a query of that type is
completed successfully the mysql_query will return TRUE allowing your
code to enter the loop -if ($result)- is checking for a TRUE condition.
Once in the loop mysql_fetch_array finds that $result is not a result
set resource and throws an error. You are compounding the problem also
by not checking for errors on INSERT, UPDATE, etc.
Do yourself a favor and re-read the link in my previous reply. There
are multitudes of info on www.php.net.
Norm
Navigation:
[Reply to this message]
|