I get this error when running this code Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource. The code is
<?php
function fetch_products(){
$sql = "SELECT 'product_id','product_name' FROM 'products'";
$result = mysql_query($sql);
$products = array();
while(($row = mysql_fetch_assoc($result)) !== false){
$products[$row['product_id']] = $row['product_name'];
}
return $products;
}
?>
I read around and someone said this is because the code isnt linking properly to the DB. However if I do
<?php
function fetch_products(){
$result = mysql_query("SELECT * FROM products");
$products = array();
while(($row = mysql_fetch_assoc($result)) !== false){
$products[$row['product_id']] = $row['product_name'];
}
return $products;
}
?>