Jump to content

cannot make error go away


jakebur01

Recommended Posts

I have looked for case sensitivity, added quotes, and removed quotes and I cannot make this error go away.

 

PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in

 

 else
   {
                           
$result2 = mysql_query("SELECT * FROM smith_prog_item WHERE item = $partnumber LIMIT 1");
while ($row2 = mysql_fetch_assoc($result2)) {
   																if($row2["type"]=="NGK")
															{ $c17="100"; $c18="$level6";}


															elseif
															($row2["type"]=="OTHER")
                 												{ $c11="$level6"; $c12="$level6"; $c13="$level6"; $c14="$level6"; $c15="$level6"; $c16="$level6"; }
   
										}
  
   
   } 

 

Also, this is within another while loop.

Link to comment
https://forums.phpfreaks.com/topic/147071-cannot-make-error-go-away/
Share on other sites

Debugging tips, echo $sql to make sure you're passing in the correct string for your query, if the mysql_query cannot execute it will kill the script and output a descriptive error message.

 

Change this:

 

$result2 = mysql_query("SELECT * FROM smith_prog_item WHERE item = $partnumber LIMIT 1");

 

to this:

 

$sql = "SELECT * FROM smith_prog_item WHERE item = '$partnumber' LIMIT 1";
echo $sql;
$result2 = mysql_query($sql) or die(mysql_error());
while ($row2 = mysql_fetch_assoc($result2)) {

 

 

Also use single quotes in your arrays: 

 

$row2["type"] 

 

to this:

 

$row2["type"]

ha ha... it echoed the $sql out 7,000 times. Thank you. It fixed it.

 

When setting $_SESSION and stuff like that, do you use single quotes there too?

 

Ex.

$_SESSION['sample'];

 

 

Oh lol, didn't know it was in a loop  :P

 

Yes, I use single quotes for every associative array.

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.