Jump to content

MySQL Error where there was never one before...


SquattingDog

Recommended Posts

Hi guys,

 

I have been lurking for a while, but this is my first post, as although I have read virtually every other thread which has the same issue (google-searched, as well as forum-searched), I cannot seem to resolve it.

 

I am getting "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\EMS\stockList.php" from the following on line 79 (the mysql_fetch_array line), and have included the code directly referenced to it:

 

$_POST['catName'] is working, as I have tried echoing it before and after, and in this instance, you can replace it with <variable>.

 

PHP Version is 5.3.0, running on WAMP 2.0 on Vista X64.  Deployation environment runs it on Win XP 32-bit (with MUCH better performance than I experience from WAMP on Vista X64).

 

77			$query = 'INSERT INTO `EMS`.`EMSCat` (`catID`, `category`, `shortcat`, `desc`) VALUES (NULL, \'' . $_POST['catName'] . '\', \'\', \'\');'; 
78			$catQuery = mysql_query($query) or die(mysql_error());
79			$catResult = mysql_fetch_array($catQuery);
80                    $querySelect = 'SELECT `EMSCat`.`catID` FROM `EMS`.`EMSCat` WHERE `EMSCat`.`category` = \'' . $_POST['catName'] .'\'';
81			$queryQuery = mysql_query($querySelect) or die(mysql_error());
82			$queryResult = mysql_fetch_array($queryQuery);
83			$cattyID = ($queryResult['catID']);
84			$queryTwo = 'INSERT INTO `EMS`.`EMSSubCat` (`catID`,`subcatID`,`subCat`,`desc`) VALUES (\'' . $cattyID . '\' , \'\' , \'' . $_POST['subcatName'] . '\',\'\');'; 
85			$queryTwoArray = mysql_query($queryTwo) or die(mysql_error());	
86			
87			//GET CATEGORY ID
88			$query = 'SELECT * FROM `EMS`.`EMSCat` LEFT JOIN `EMS`.`EMSSubCat` ON `EMSCat`.`catID` WHERE `EMSCat`.`category` = \'' . $_POST['catName'] . '\' AND `EMSSubCat`.`subCat` = \'' . $_POST['subcatName'] . '\'';
89			$result=mysql_query($query) or die(mysql_error());	
90			$row = mysql_fetch_array($result);
91			$catID=$row['catID'];
92			$subcatID = $row['subcatID']; 	

 

Things I have tried:

 

Changing the permissions, username, password and IP for connecting - connection is fine, same issue arises.

Adding a new call/manual connection before the query, again connection is fine, same issue arises.

Changing quotation marks to double quotes, and removing quotes wherever possible, as I was able to get this to work using phpMyAdmin when using no escaping of quotation marks - but this doesn't work on the actual code and also gave me '' . <variable> . '' in the database, instead of just <variable>.

 

Further information:  Despite this error, the `category` gets inserted into the database, and the `subCat` information gets inserted.

 

I can post the whole lot of the code, if required.

 

Things which have changed:  data in the EMSItem table has changed (different supplier), but is being imported with no single or double-quotes, and thus should not be affecting this.

 

I need this up and running asap, as I have already spent two weeks trying to resolve this to no avail!  Any help is greatly appreciated! :)

 

PS:  I am a relative noob to PHP/MySQL, and have had to take this over from my previous business partner who is no longer in the business.

77         $query = 'INSERT INTO `EMS`.`EMSCat` (`catID`, `category`, `shortcat`, `desc`) VALUES (NULL, \'' . $_POST['catName'] . '\', \'\', \'\');';
78         $catQuery = mysql_query($query) or die(mysql_error());
79         $catResult = mysql_fetch_array($catQuery);

 

In line 79, $catQuery is the result of executing an INSERT statement.  The mysql_query() function returns a boolean in this case (true or false).  There are no rows to fetch so you should not be calling mysql_fetch_array() here.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.