You are here: Re: PHP/MySQL warnings about results « PHP Programming Language « IT news, forums, messages
Re: PHP/MySQL warnings about results

Posted by Tom on 11/21/07 19:26

On Wed, 21 Nov 2007 08:43:08 -0800 (PST), bruno_guedesav wrote...
>
>I've made a function to fetch all results as an array of result-
>arrays. Getting the result arrays is easy, via mysql_fetch_array, and
>function itself is quite simple, as follows:
>
>function db_query($db, $query)
>{
> $result = mysql_query($query, $db);
> $res_array = array();
>
> if ($result) //it is a search
> {
> while($data = mysql_fetch_array($result,MYSQL_ASSOC))
> array_push($res_array,$data);
> }
>
> return $res_array;
>}
>
>But there's a slight problem: when the query in question is an INSERT,
>UPDATE or DELETE query, PHP will show me a warning saying:
>
>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?


I don't think you're suppose to use the mysql_fetch_array() function on INSERTs
since that function is intended to capture the results from a query, rather than
adding, deleting , or updating.

I normally use mysql_query() for INSERTS and there's a few other functions like
mysql_error and mysql_result you can use in conjunction with that.

Tom
--
NewsGuy Free Trial Accounts
Now a massive 20 Gigabytes of unrestricted downloads !
http://newsguy.com/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация