Hey ,

I'm having trouble showing data from my data base in php. i always get the " No database selected " line and also i was wondering why the second echo doesn't show the result is :

first echo
No database selected

this is my code

<?php
	require($_server["DOCUMENT_ROOT"]."/config/db_config.php");
	$connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");
	mysql_select_db($site, $connection) ;
$query = "SELECT * FROM `example`"; 
	 echo "first echo <br>";
	$result = mysql_query($query) or die(mysql_error());
    
     echo "second echo<br>";

	$row = mysql_fetch_array($result) or die(mysql_error());
	echo $row[name]. " - ". $row[age];

?>

I checked the database name and the field names.
also checked the mysql user account and even made a new one but still nothing

I guess there are other people who banged their heads against that wall at some point with this problem :icon_wink:

well i cannot say without revealing the "db_config.php" file..

but try writing the name of the db manually and see if it works first.. if it does then, the $site variable surely is not working properly, maybe it's overwritten by something else in the "db_config.php" file.

well i cannot say without revealing the "db_config.php" file..

but try writing the name of the db manually and see if it works first.. if it does then, the $site variable surely is not working properly, maybe it's overwritten by something else in the "db_config.php" file.

I have no problem inserting data into the database so the connection is working

<?php 
	$db_host = "localhost";
	$db_user = "mark";
	$db_password = "blob";
	$db_name = "site";
	
	?>

this is the db_config file

the user privileges are select Y, update Y , insert Y ,delete Y

I don't see the variable "$site" in your config file.. so you're basically selecting nothing as a database.

if you want to connect to the database:
mysql_select_db($db_name, $connection) ;

OR

mysql_select_db('site', $connection) ;

I don't see the variable "$site" in your config file.. so you're basically selecting nothing as a database.

if you want to connect to the database:
mysql_select_db($db_name, $connection) ;

OR

mysql_select_db('site', $connection) ;

:icon_mrgreen: it's working now . Thanks a lot :icon_cheesygrin:
once again the machine got the best of me :D

lol it happens :)

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.