2
<?
require_once('etcore.php');
mysql_connect($dburl,$dbuser,$dbpass) or die(mysql_error()); 
mysql_select_db("rshost") or die(mysql_error());
$username=strtoupper(clean($_POST['username']));
$password=md5($_POST['password']);
$andover = mysql_query("SELECT * FROM users WHERE usernameupper='$username' AND password='$password'") or die(mysql_error().__LINE__);
$numberofthings = mysql_num_rows($andover) or die(mysql_error().__LINE__);
if ($numberofthings = 1) {
    $getit=mysql_fetch_array($andover) or die(mysql_error().__LINE__);
    $_SESSION['id'] = $getit['id'];
    header('Location: index.php');
}
else {
?>
<h1>Login:</h1>
<img src='http://media.idownloadblog.com/wp-content/uploads/2011/12/Warning.png' width="25" height="25" />
<strong style="color:#F03;">Incorrect Username and/or Password </strong><br>
<form method="POST" action="login.php">
Username: <input name="username" type="text" /><br />
Password: <input name="password" type="password" /><br />
<input name="submit" type="submit" value="Log In!" /><br />
</form>
<? } ?>

This is the code I am using. Whenever I run the code, I get the error "No database selected" on line 7. Any help would be appreciated. Thanks! BTW: Db user, pass and URL are all in the 'etcore.php' file, so it is not a problem there. I have also tried replacing those variables with strings and get the same error.

2
  • Which one is line 7? the $andover = mysql_query(...) one? Commented May 19, 2012 at 14:36
  • 4
    Try saving the connection handle and passing it explicitly. Any change you are creating a new connection to the database in the clean function? Anyway, worth trying: $res = mysql_connect(); mysql_select_db("rshost", $res); mysql_query(..., $res); Commented May 19, 2012 at 14:39

2 Answers 2

5

How about:

mysql_select_db("rshost", mysql_connect($dburl,$dbuser,$dbpass))

or even better:

$handle = mysql_connect($dburl,$dbuser,$dbpass);
mysql_select_db("rshost", $handle);

And maybe for a better knowledge and understanding: manual page

in the section parameters so it would be clear why it may OR may not work without using the $handle argument

Sign up to request clarification or add additional context in comments.

Comments

0

Give the database privileges. May be you don't have the user permission to access database, check this

mysql> grant all privileges on Databasename.* to 'username'@'localhost' identified by password

1 Comment

This actually solved my problem! Apparently old mysql functions does not tell the truth on error - jet another reason why we shouldn't use them!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.