Why does it say: No database selected?

General discussions related to php

Moderators: macek, egami, gesf

Post Reply
User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Post by Joan Garnet » Sat Jan 11, 2003 3:43 pm

Try this ->

Code: Select all

$connect = mysql_connect($server,$login,$pass);     
mysql_select_db($db,$connect);
$query = "SELECT id, ........

User avatar
WiZARD
Moderator
Moderator
Posts: 1256
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: Why does it say: No database selected?

Post by WiZARD » Sun Jan 12, 2003 4:36 am

Try change at this:

Code: Select all

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

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Post by Joan Garnet » Sun Jan 12, 2003 1:31 pm

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: Select all

<?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!

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests