I get these errors in a script of mine:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\www\vhosts\myradiostation\test.php on line 13

and my original page (included in another page):

<?php
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","PASSWORDREMOVED"); 
	
//select which database you want to edit
mysql_select_db("myradio"); 

//select the table
$result = mysql_query("select * from presenters;");

//grab all the content
while($r=mysql_fetch_array($result)) 
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
   $shows=$r["shows"];
   $onair=$r["onair];
   $images=$r["image"];
   $showdesc=$r["showdesc"];
	echo "<div class=\"divider\"></div>
		<div class=\"main\" style=\"width:552px;\">
			<img src=\"$images\" width=115 height=60>
			<div class=\"time\">$onair</div>
			<div class=\"show\"><h3><b>$shows</b></h3>
				<p>$showdesc</p></div>
			<div class=\"footer\"></div>
		</div>";
	}
	?>

How do I get the MySQL and PHP to work properly with this?

Dani AI

Generated

The warning means the value passed into the fetch function is not a valid result resource — in short, the SELECT did not return a usable result (or the variable never held one). Common root causes are: the query failed (syntax, wrong table/column names, permissions), the database connection or database selection failed, or a PHP syntax error earlier in the file stopped execution and left variables unset.

Good pointers already in the thread: flagged the query string issue, recommended running the same query directly in the database to verify the table and column names, and suggested surfacing the database error message so the real failure is visible. Add one more: inspect the PHP snippet for unbalanced quotes or missing braces — an unclosed string or bracket will break parsing and make later variables invalid.

Quick troubleshooting checklist

  • Confirm the connection and database selection succeed (check their return values).
  • Run the SELECT in the DB client (phpMyAdmin/CLI) to confirm the table and column names and permissions.
  • After issuing the query, check whether it returned false; if so, dump the DB error to see the cause.
  • Scan the PHP for syntax problems (unmatched quotes, missing semicolons, incorrect array index quoting).
  • If moving from Windows to Linux hosting, remember MySQL table name sensitivity can differ.

Example (modern, safe pattern using mysqli and explicit checks):

$conn = mysqli_connect('host','user','pass','database');
if (!$conn) { die('Connect error: ' . mysqli_connect_error()); }

$sql = "SELECT col1, col2 FROM your_table";
$res = mysqli_query($conn, $sql);
if (!$res) { die('Query error: ' . mysqli_error($conn)); }

while ($row = mysqli_fetch_assoc($res)) {
    // use $row['col1'], $row['col2']
}

Notes: migrating from the old mysql_ extension to mysqli or PDO gives clearer errors and safer code. If the snippet still fails after these checks, the most common immediate fix is correcting any unbalanced quotes in the PHP (for example an array index missing its closing quote), then re-running the query and checking the DB error output.

Recommended Answers

All 4 Replies

This line:

$result = mysql_query("select * from presenters;");

should be:

$result = mysql_query("select * from presenters");

I got another error, the error being this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\www\vhosts\\showfile.php on line 13

.
Here's my code:

<?php
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","PASSWORDREMOVED"); 
	
//select which database you want to edit
mysql_select_db("myradio"); 

//select the table
$result = mysql_query("select * from presenters");

//grab all the content
while($r=mysql_fetch_array($result)) 
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
{
   $shows=$r["shows"];
   $onair=$r["onair];
   $images=$r["image"];
   $showdesc=$r["showdesc"];
	echo "<div class=\"divider\"></div>
		<div class=\"main\" style=\"width:552px;\">
			<img src=\"$images\" width=115 height=60>
			<div class=\"time\">$onair</div>
			<div class=\"show\"><h3><b>$shows</b></h3>
				<p>$showdesc</p></div>
			<div class=\"footer\"></div>
		</div>";
	}
	?>

I got another error, the error being this:
.
Here's my code:

<?php
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","PASSWORDREMOVED"); 
	
//select which database you want to edit
mysql_select_db("myradio"); 

//select the table
$result = mysql_query("select * from presenters");

//grab all the content
while($r=mysql_fetch_array($result)) 
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
{
   $shows=$r["shows"];
   $onair=$r["onair];
   $images=$r["image"];
   $showdesc=$r["showdesc"];
	echo "<div class=\"divider\"></div>
		<div class=\"main\" style=\"width:552px;\">
			<img src=\"$images\" width=115 height=60>
			<div class=\"time\">$onair</div>
			<div class=\"show\"><h3><b>$shows</b></h3>
				<p>$showdesc</p></div>
			<div class=\"footer\"></div>
		</div>";
	}
	?>

execute the

select * from presenters

directly into the MySQL , and see if there you get the same error, then you must check with your table name.
If such table even exists or not.

try to use mysql_error in query to confirm if your query is valid or not,
Example:

...
//select the table
$result = mysql_query("select * from presenters")or die(mysql_error());
...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.