Jump to content

please help with error


webguync

Recommended Posts

need to know why I am getting this error.

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /products.php on line 15

 

here is the code

<?php
ini_set("display_errors","1");
ERROR_REPORTING(E_ALL);
$link = mysql_connect("localhost","username","password");

mysql_select_db("TESTING");

$query = 'SELECT * FROM Products';
$results = mysql_query($query);

echo "<?xml version=\"1.0\"?>\n";
echo "<products>\n";
while ($line = mysql_fetch_assoc($results)) {
echo "<item>" . $line["product"] . "</item>\n";
}

echo "</products>\n";
mysql_close($link);
?>



Link to comment
https://forums.phpfreaks.com/topic/175806-please-help-with-error/
Share on other sites

while ($line = mysql_fetch_assoc($results))

 

Shouldn't you be using == instead of = ?

No, because the OP is trying to store the value returned by mysql_fetch_assoc($results) in the $line variable, so he is correct to use assignment = rathe rthan comparison ==.

Hi webguync,

 

The single = is the correct syntax for this query.

 

Are you sure the 'Products' table exists?  (With the capital P)?

 

Also, are you sure you are connecting to the database?

 

Amend your code to read:

 

<?php
ini_set("display_errors","1");
ERROR_REPORTING(E_ALL);
$link = mysql_connect("localhost","username","password") or trigger_error('Query failed: ' . mysql_error());

mysql_select_db("TESTING") or trigger_error('Query failed: ' . mysql_error());

$query = 'SELECT * FROM Products';
$results = mysql_query($query);

echo "<?xml version=\"1.0\"?>\n";
echo "<products>\n";
while ($line = mysql_fetch_assoc($results)) {
echo "<item>" . $line["product"] . "</item>\n";
}

echo "</products>\n";
mysql_close($link);
?>

 

That way you will be able to whether your code is actually connecting and selecting the database.

 

Hope this helps.

need to know why I am getting this error.

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /products.php on line 15

Generally it means that your SQL query has failed for some reason. Try doing

$results = mysql_query($query) or die('ERROR: '.mysql_error().' in '.$query);

 

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.