douyuan9512 2014-09-14 18:19
浏览 138
已采纳

没有选择数据库[关闭]

include 'connect.php';

        $sql = "SELECT 
                    user_id,
                    user_name,
                    user_level
                FROM
                    users
                WHERE
                    user_name = '" . mysql_real_escape_string($_POST['user_name']) . "'
                AND
                    user_pass = '" . sha1($_POST['user_pass']) . "'";

        $result = mysql_query($sql);
        if(!$result)
        {

            echo 'Something went wrong while signing in. Please try again later.';
            //echo mysql_error(); //debugging purposes, uncomment when needed
        }

Can someone please have a look at this and fix the error. This is the error: No Database selected. I took signin.php from an online tutorial which might be outdated. It would help if someone told me if it would be ok to keep $server as localhost. Please remember that I'm new to programming and may make basic mistakes. This is connect.php: It works, I've tested it with signup.php

<?php
//connect.php
$server = 'localhost';
$username   = 'xxx';
$password   = 'xxx';
$database   = 'xxx';
$mysqli = new mysqli("$server", "$username", "$password", "$database");
if(!mysqli_connect($server, $username,  $password))
{
exit('Error: could not establish database connection');
}
?>
  • 写回答

2条回答 默认 最新

  • doubiao7267 2014-09-14 18:23
    关注

    You must set the $database in the mysqli_connect

    if(!mysqli_connect($server, $username,  $password, $database))
    

    And there is no need for this line since you don't use this variable in your code:

    $mysqli = new mysqli("$server", "$username", "$password", "$database");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数