<?php
		
// connect to database
 
$con = mysql_connect('localhost', 'root', '');
	  
	if (!$con) {
die('Could not connect: ' . mysql_error());
				}
	echo 'Connected successfully <br>';

  $db_selected = mysql_select_db("template", $con);

	if (!$db_selected)
	{
	die ("Can't use template : " . mysql_error());
  				}
else echo 'database connected <br>';
				  		mysql_close($con);

				
		
			//LOAD USER		
$result = mysql_query("SELECT * FROM kategori_berita") or die(mysql_error());
while ($data = mysql_fetch_array($result)){
	?>

The following message appears on my site:

Connected successfully
database connected
No database selected


I wonder if the database is selected yet? die (mysql_Error()) display No database selected while on other error shows database connected/selected. Since like both of them contradict each other. What's wrong with the codes?

Thanks.

I think the problem is that
you do this:

mysql_close($con);

before execute your query so you don't have an active connection.
Try to put this line after query execution :

$result = mysql_query("SELECT * FROM kategori_berita") or die(mysql_error());
mysql_close($con);
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.