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