I'm learning PHP & MySQL. While trying to folllow a tutorial I am not getting the erxpected result which is simply to retrieve a little data out of a table with a query.
Here is my PHP code:

<?php
//1. Create a database connection
$connection = mysql_connect("localhost", "kingdomc_mtech", "busine$$");
if (!$connection)
{
die("Database connection failed: " . mysql_error());
}

//2. Select a database to use
$db_select = mysql_select_db("kingdomc_learning", $connection);
if (!$db_select)
{
die ("Database selection failed: " . mysql_error());
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SQL lesson1</title>
</head>

<body>
<?php
	//3. Perform database query
	$result = mysql_query("SELECT * FROM subjects", $connection);
	if(!$result)
	{
	die ("Database query failed: " . mysql_error());
	}
	//4. Use returned data
	while ($row = mysql_fetch_array($result));
	{
	echo $row[0]." ".$row[2]."<br/>";
	}
	?>
</body>
</html>
<?php
//5. Close connection
mysql_close($connection);
?>

and i have attached a screenshot of my very simple table. Thanks for the time and help.

Member Avatar for diafol

What's the problem? Any error messages?

What's the problem? Any error messages?

No error message. I'm not getting any data returned. When I load and even refresh my page its just blank.

<?php
//1. Create a database connection
$connection = mysql_connect("localhost", "kingdomc_mtech", "busine$$");
if (!$connection)
{
die("Database connection failed: " . mysql_error());
}

//2. Select a database to use
$db_select = mysql_select_db("kingdomc_learning", $connection);
if (!$db_select)
{
die ("Database selection failed: " . mysql_error());
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SQL lesson1</title>
</head>

<body>
<?php
	//3. Perform database query
	$result = mysql_query("SELECT * FROM subjects", $connection);
	if(!$result)
	{
	die ("Database query failed: " . mysql_error());
	}
	//4. Use returned data
	while ($row = mysql_fetch_array($result));
	{
	echo $row[0]." ".$row[2]."<br/>";
	}
	?>
</body>
</html>
<?php
//5. Close connection
mysql_close($connection);
?>

line 27, try

$result = mysql_query("SELECT * FROM subjects" );
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.