31/03/2002 01:02:04, "Patrick Hartnett" <[EMAIL PROTECTED]> wrote:

You Need to use the command
Mysql_Select_Db("$db_name") Or Die("Unable to connect!");

after connect with mysql

I use something like this:

mysql_connect($db_host, $db_user, $db_pass) or die ("Unable to connect!");
Mysql_Select_Db("$db_name") Or Die("Unable to connect!");

I don't use a $connection like var.


>here is a function used to authenticate users against mysql database.  
>Problem is, I am not connecting for some reason.  I have the db variables:
>$db_host
>$db_user
>$db_pass
>$db_name
>
>They are populated from an include ("x.php") in the beginning of the php 
>section.  It is getting past the connect statement, but it is not selecting 
>the proper database, and gives a:
>
>"Error in query: No Database Selected"
>
>in the error trap below (die).  Any ideas what is wrong?  Am I missing some 
>syntax, or what?
>Thanks.
>
>Patrick
>
>######################################
>
>function authenticate($user, $pass)
>{
>
>       // check login and password
>       // connect and execute query
>       $connection = mysql_connect($db_host, $db_user, $db_pass) or die ("Unable 
>to connect!");
>       $query = "SELECT id from users WHERE username = '$user' AND password = 
>PASSWORD('$pass')";
>       mysql_select_db($db_name);
>       //mysql_select_db("devweb"); <--what it should be, from file
>       $result = mysql_query($query, $connection) or die ("Error in query: " . 
>mysql_error());
>
>       // if row exists -> user/pass combination is correct
>       if (mysql_num_rows($result) == 1)
>       {
>               return 1;
>       }
>       // user/pass combination is wrong
>       else
>       {
>               return 0;
>       }
>}
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
>
>
>-- 
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to