表' database_name.username'不存在

时间:2015-08-13 10:48:17

标签: php mysql database

我尝试将我的html登录文件连接到phpmyAdmin数据库名称" 6470" - 表" 6470练习"通过这个php文件。

结果是"表' 6470.username'不存在"。我该如何解决这个问题?

这是我的代码:

define('DB_HOST', 'localhost');
define('DB_NAME', '6470');

define('DB_USER','root');
define('DB_PASSWORD','');

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL 1: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL 2: " . mysql_error());
/*
$ID = $_POST['user'];
$Password = $_POST['pass'];
*/

function SignIn()
{
    session_start(); //starting the session for user profile page
    if(!empty($_POST['user'])) //checking the 'user' name which is from Sign-In.html, is it empty or have some text
    {
        $query = mysql_query("SELECT * FROM UserName where userName = '$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error());
        $row = mysql_fetch_array($query) or die(mysql_error());
        if(!empty($row['userName']) AND !empty($row['pass']))
        {
            $_SESSION['userName'] = $row['pass']; echo "SUCCESSFULLY LOGIN TO USER PROFILE PAGE...";
        } else {
            echo "SORRY... YOU ENTERED WRONG ID OR PASSWORD... PLEASE RETRY...";
        }
    }
}
if(isset($_POST['submit']))
{
    SignIn();
}

1 个答案:

答案 0 :(得分:1)

尝试更换:

$query = mysql_query("SELECT * FROM UserName where userName = '$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error());

使用:

$query = mysql_query("SELECT * FROM 6470exercises where userName = '{$_POST[user]}' AND pass = '{$_POST[pass]}'") or die(mysql_error());