Re: MySQL Connection Error - mysql_select_db

From: Date: Sun, 31 Mar 2002 04:14:31 +0000
Subject: Re: MySQL Connection Error - mysql_select_db
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-90852@lists.php.net to get a copy of this message
I don't think those variables are readable in the function. Not totally sure though. Tyler Longren Captain Jack Communications tyler@captainjack.com www.captainjack.com ----- Original Message ----- From: "Patrick Hartnett" <irishprogramming@hotmail.com> To: <php-general@lists.php.net> Sent: Saturday, March 30, 2002 10:02 PM Subject: [PHP] MySQL Connection Error - mysql_select_db > 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 >

« previous php.general (#90852) next »