MYSQL PHP未选择数据库-找不到错误 [英] MYSQL PHP No Database Selected - Can't Find Error

查看:210
本文介绍了MYSQL PHP未选择数据库-找不到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我正在使用的代码.每当我运行代码时,我都会在第7行收到错误未选择数据库".任何帮助将不胜感激.谢谢!顺便说一句:Db用户,通过和URL都在'etcore.php'文件中,所以这不是问题.我还尝试用字符串替换这些变量,并得到相同的错误.

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.

推荐答案

怎么样:

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

甚至更好:

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

也许为了获得更好的知识和理解: 手册页

And maybe for a better knowledge and understanding: manual page

参数部分中 因此很清楚为什么不使用$handle参数

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

这篇关于MYSQL PHP未选择数据库-找不到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆