0
<?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.

Edited by davy_yg: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by antonioatt
0

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);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.