Jump to content

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

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.