“没有选择数据库”问题

My developing environment is based on EasyPHP 12 and PHPdesigner on windows XP SP3. I am working on a registration / login solution, and I successfully completed the "sign up" part of it with a very basic script that used to work fine. For some reason I had to switch machine and, when I copied all the pertinent files back to my first station, I have got the "No database selected" message. I have tried everything to fix the issue, including creation of a brand new DB with only one table so far (users). My Connection file (db_connection.php) is as follows:

DEFINE ('DB_USER', 'superuser'); 
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'hf_databank');

// Make the connection:

$db_connect = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// Check connection
   if (mysqli_connect_errno($db_connect))                        {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

// Let us select the database (just in case you want to change it): 

    $db_select = mysqli_select_db ($db_connect, DB_NAME) OR die;

and it seems to work fine.

Then, going back to my index.php file, it looks like the following validation lines are creating issues that I am not able to fix:

include_once '../includes/db_connection.php';
include_once '../includes/functions.php';

$action = array();
$action['result'] = null;
$text = array();


//check if the form has been submitted

if(isset($_POST['signup'])){

//cleanup the variables  and prevent mysql injection (this uses the function "clean" defined in functions.php file)

    $username = clean($_POST['username']);
    $password = clean($_POST['password']);
    $email = clean($_POST['email']);


    //Validation 1: Let’s say the user submits the form without a username. Our statement is going to run the 
    //code below. 
if(empty($username)){ $action['result'] = 'error'; array_push($text,'Please set a  valid username'); }
if(empty($password)){ $action['result'] = 'error'; array_push($text,'Please define a password'); }
if(empty($email)){ $action['result'] = 'error'; array_push($text,'Please set a valid email address'); } 




     $query = mysql_query("SELECT * FROM `users` WHERE username = '$username' OR email = '$email'") or die (mysql_error()); // mySQL Query    
        $row = mysql_num_rows($query); // Checks to see if anything is in the db.


       if ($row > 0) { 
            $action['result'] = 'error'; array_push($text,'existing username/email; 
            }

it looks like the script is stuck at the "$query" step, where I get the error message.

I have tried several approaches to pinpoint the issue but still not able to understand where the problem is. I am also able to connect to the database (hf_databank) without a problem, database structure looks ok. Any help would be really appreciated !

in the second part you are using mysql_ and to connect you use mysqli_

use mysqli_ also for your query

$query = mysqli_query($db_connect,"SELECT * FROM `users` WHERE username = '$username' OR email = '$email'") or die (mysqli_error()); // mySQL Query    
        $row = mysqli_num_rows($query);

If it was working properly in your previous machine then I think this solution may help you to select database. Check step by step the information step by step enter image description here

Replace all the mysql_* used in your script and replace it with mysqli_*.

For example :

$query = mysqli_query($db_connect, "SELECT * FROM `users` WHERE username = '$username' OR email = '$email'"");

I'd suggest you to use the MySQLi class for the connection. It makes coding easier! And especially secure by the use of placeholders (?). For more info, visit PHP.net - Prepared Statements in MySQLi

And also, mysql_* is deprecated. So, its better to leave old practices of using them!