davidf85 Posted February 18, 2012 Share Posted February 18, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/257247-mysql-error/ Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2012 Share Posted February 18, 2012 I've removed your DB hostname, username and password, but you really need to go change your login credentials now. They were posted on the internet for a while, after all. Quote Link to comment https://forums.phpfreaks.com/topic/257247-mysql-error/#findComment-1318612 Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2012 Share Posted February 18, 2012 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 . . . Quote Link to comment https://forums.phpfreaks.com/topic/257247-mysql-error/#findComment-1318615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.