Why does it say: No database selected?

A

Anonymous

Guest
Try this ->
Code:
$connect = mysql_connect($server,$login,$pass);	  
mysql_select_db($db,$connect);
$query = "SELECT id, ........
 
Try change at this:
Code:
<?php
$server = ("Q3L");
$username = ("acme");
$password = ("******");
$db = ("news");

//Maak verbinding met server
$connection= mysql_connect($server, $username, $pass) or die ("Sorry, connection not establishing!<BR>");

//selecteer database
mysql_select_db($db) ro die ("Sorry, database:<b>$db</b> not have exist<BR>");

//Selecteer alle id's en titels van je tabel!
$query = "SELECT id, titel FROM nieuws";

//Voer query uit!
$result = mysql_query($query, $connection) or die ("Query failed! : ".mysql_error());

//Maak OO van $result 
while ($obj = mysql_fetch_object($result)){

   //Echo titel met link naar toonbericht.php
   echo '<a href="toonbericht.php?id='.$obj->id.'">'.$obj->titel.'</a><br>';
}

?>

And before to do this check you database.... maby some mistake in name of database....
And once table and database it is a diffirent....
 
It should work 8O
This is the right syntax, and nothing else can be done, I mean, you connect to the server, then connect to the database and make the query.
Try this:

Code:
<?php 
$server="localhost";
$login="xxxxxxx";
$pass="xxxxxxx";
$db="xxxxxxx";
$table="my_table";

$user = $HTTP_POST_VARS["user"];
$passwrd = $HTTP_POST_VARS["hex_pass"];

$conection=mysql_connect($server,$login,$pass) or die("<h3>Couldn't connect to the database</h3></BODY></HTML>"); 	  
mysql_select_db($db,$conection)or die ("<h3>Couldn't select the database</h3></BODY></HTML>");
$sql = "SELECT * FROM ".$table;
$result= mysql_query($sql,$db) or die ("<h3>Couldn't select information</h3></BODY></HTML>"); 
if ($row = mysql_fetch_array($result)){
	do{
		echo $row[0]."\n";
	}while	($row = mysql_fetch_array($result));
}else{
	echo "No data found";
} 
mysql_close($db); 
?>

And tell us which message appears when you run the script.
bye!
 
Back
Top