特定の値がデータベースの列にあるかどうかを確認する PHP 関数を作成しようとしています。関数は引数$userNameを取り、データベースの列でチェックされる$link場所が対象です。これが私がこれまでに得たものです:$userNameuserid$link
<?php  
/*This function checks to see if the username is already in use  
INPUT: the userName to check for and a link to the database  
OUTPUT: true if there are no other users registered with userName  
*/  
function isUnique($userName, $link)  
{  
    $result = !!mysqli_fetch_row(mysqli_query($link, 'SELECT `userid`  
    FROM `login`  
    WHERE `userid` = \''.$userName.'\''));  
    return $result;  
}  
echo '<html><head><title>testing</title><body>';  
$uName = $_POST['us'];  
$pass = $_POST['pa'];  
//database work  
$link = mysqli_connect("localhost:3306", "root", "");  
if(!$link)  
    die('Could not connect to MySQL: '.mysql_error());  
$db_selected = mysqli_select_db($link, 'Accounts');  
if(!$db_selected)  
    die('Can\'t use Accounts: '.mysql_error());  
echo '<br />Using Accounts database<br />';  
if(isUnique($uName, $link))  
{  
    echo 'username is unique!<br />';  
}  
else  
{  
    echo 'username is not unique!<br />';  
}  
mysqli_close($link);  
echo '</body></html>';  
?>
ページには、指定されたユーザー名が一意ではないと常に表示されます。