0
嘗試:獲得價值爲PHP數組
$existing_users=array('value','value','value', 'value'...)
PHP腳本:通過使用下面的腳本查詢到一個數組
希望得到的輸出這樣得到的所有用戶
<?php
require_once('../../../inc/db/dbc.php');
$connect = mysql_connect($h, $u, $p) or die ("Cant Connect to Database.");
mysql_select_db($db);
$q = mysql_query("SELECT uUName FROM User");
$existing_users=array(
while ($row = mysql_fetch_array($q, MYSQL_NUM)) {
echo " '$row'.','";
}
);
// $existing_users=array('joe','warren','tim');
# ^^^^ manual way of doing it
//value got from the get metho
$user_name=$_POST['user_name'];
//checking weather user exists or not in $existing_users array
if (in_array($user_name, $existing_users))
{
//user name is not availble
echo "no";
}
else
{
//user name is available
echo "yes";
}
?>
我該如何做到這一點?我知道我的陣列陣列有點偏離那裏,我該如何解決這個問題?
感謝
如果你想檢查用戶名是否可用,你可以這樣選擇:'SELECT uUName FROM User WHERE uUName ='$ user_name';'如果select有數據,則用戶名不可用。當然,你必須首先驗證你的輸入數據。 – EmCo