Hey everyone, new guy here, having an issue with a section of code... decided one day to just stop working, nothing was changed.

the code is

$query = mysql_query("SELECT * FROM products");
							while ($row = mysql_fetch_array($query)){
							$productname = $row['name'];
							$productinci = $row['inci'];
							$productdescription = $row['description'];
							$functions = $row['functions'];
							$pid = $row['id'];
							$id = "<A href=\"processdeleteproduct.php?id=$pid\">Delete product</A>";
							$editid1 = "<A href=\"editindvproduct.php?id=$pid\">Edit product</A>";

the error is:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\---\allsuppliers.php on line 102 -(Line 102 is the start of the query)

Any help would be appreciated. Cheers.
Scaasiboi

Recommended Answers

All 4 Replies

Hi Dear,

Try to use mysql_fetch_array() with MYSQL_NUM or mysql_fetch_array() with MYSQL_ASSOC or mysql_fetch_array() with MYSQL_BOTH

As in ur code ur r fetching the records by the field name so use MYSQL_ ASSOC().

For Example you can check this link
http://php.net/manual/en/function.mysql-fetch-array.php

It seems your query is not proper.
Replace ut code with below code to see mysql error.

$query = mysql_query("SELECT * FROM products") or die(mysql_error());

Hello Scaasiboi,

In the above, the mysql_query() function is sending the specific query to the database and returning a 'resource identifier', which is being set as the value of $query. These are not the results themselves -- if you echo $queryat this point, you'll get 'Resource id #x'. The mysql_fetch_array() function in your while loop takes this resource identifier and creates an array of the actual db contents that you can use.

If your mysql_query() function fails to get a resource id, it returns a boolean FALSE instead. FALSE, of course, isn't a resource identifier, so when you try to pass it to mysql_fetch_array(), it will cough up the 'not a valid result resource' error. So all of you are getting failures in your mysql_query() function.

Using 'or die(mysql_error())' at the end of your mysql_query() call, instead of setting $query to FALSE, kill the script and, more importantly, return a more descriptive error message.

Cheers guys, i know what the issue was, it was actually outputting an incorrect error because of something earlier in the code. The config file wasn't being called in time for the values of the SQLSERVER SQLUSER and SQLPASSWORD variables.

All is working now, thanks for all your responses!

Scaasiboi(Jack)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.