Jump to content

MySQL Error


davidf85

Recommended Posts

I am getting this error:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/20/8917120/html/goldenfruit/test.php on line 11

 

for this code:

 

 

<?php

 

$connect = mysql_connect('DB credentials removed');

 

if (!$connect) {

  die('Could not connect: ' .mysql_error());

}

 

 

$data = mysql_query("SELECT * FROM fruits");

$row  = mysql_fetch_row($data);

 

echo $row[0];

 

echo hello;

 

 

?>

 

 

I cannot seem to find the error in this.

Can anyone help?

Link to comment
https://forums.phpfreaks.com/topic/257247-mysql-error/
Share on other sites

As far as the problem goes, it's most likely because you haven't selected the database to use, with mysql_select_db. But to add to that, don't get in the bad habit of nesting your query string within the mysql_query() function. Doing so makes it impossible to echo the query string when things go wrong and you need to start debugging. Instead, form the query string in a variable, and use the variable to execute the query.

 

mysql_connect('db_host', 'username', 'pass');
mysql_select_db('food');

$value = 'red'
$query = "SELECT color, vegetable FROM side_dishes WHERE color = '$value' ORDER BY vegetable ASC";
$result = mysql_query($result);
// etc . . .

Link to comment
https://forums.phpfreaks.com/topic/257247-mysql-error/#findComment-1318615
Share on other sites

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.