1.11M Members

no database selected problem

 
0
 

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:

 
0
 

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.

 
0
 

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

 
0
 

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) ;

 
0
 

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

 
0
 

lol it happens :)

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: