使用PHP在mysql数据库中搜索重复的user_id

I'm trying to do something that I think should be pretty basic, but I'm not having any luck. I want to create a unique user id for each user. I have the code written for creating a random, 7-digit number, and I need to just check the number against the database to see if that user id already exists (unlikely since I'm using a 7-digit number, but I have to check anyway).

Here's the relevant portion of the code:

 <?php

require("config.inc.php");

$test_number = "1234567"; 

$query = mysql_query("SELECT user_id FROM users WHERE user_id ='$test_number'");

echo $test_number; 

if(mysql_num_rows($query) != 0){
   echo "
 number already exists.";
}else{
   echo "
 number not found"; 
}

?>

I'm just using test number as a placeholder. I've manually added the number 1234567 to my database, but every time I run the code, the second prong of the if-statement gets called, so the out put is always "1234567 number not found" even though that number does exist for a user in my database.

The require ("config.inc.php") line works because I have other .php files that use that same file and connect to the database just fine, so I don't think it's a connection issue.

Please try with code

<?php

$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

 mysql_select_db('tsg_userlogin_dev', $link) or die('Could not select database.');

$test_number = "88888"; 

$query = mysql_query("SELECT EmployeeId FROM tsguser WHERE EmployeeId ='$test_number'");

echo $test_number; 

if(mysql_num_rows($query) != 0){
   echo "
 number already exists.";
}else{
   echo "
 number not found"; 
}

</div>