Trying to: get all users by using the query in the below script into an array
Looking to get output like this:
$existing_users=array('value','value','value', 'value'...)
Php Script:
<?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";
}
?>
How do I accomplish this? I know my while/array formation is a bit off there, how do I fix this?
Thanks
SELECT uUName FROM User WHERE uUName = '$user_name';
If the select has data, the username is not available. Of course, you have to validate your input data first. – EmCo Nov 22 '11 at 0:41