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
Share on other sites

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.

Link to comment
Share on other sites

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);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.