<?php
// Developed by Roshan Bhattarai
// Visit http://roshanbh.com.np for this script and more.
// This notice MUST stay intact for legal use
//this varible contains the array of existing users
$existing_users=array('');
//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";
}
?>
<?php
$sql="SELECT username FROM modx_web_users";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)) {
$return[] = $row;
}
$existing_users=$return[];
//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";
}
?>
<?php $sql="SELECT username FROM modx_web_users"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $return[] = $row; } $existing_users=$return[]; //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"; } ?>
нет все равно без результатов!
упс - ошибка
$existing_users=$return[];
нужно
$existing_users=$return;
Работает
<?php
$sql="SELECT username FROM modx_web_users";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)) {
$return[] = $row;
}
$existing_users=$return;
//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";
}
# add the output
echo var_dump($return);
echo "<br/>".$_POST['user_name'];
?>
Так. Попробуем потестировать.
<?php $sql="SELECT username FROM modx_web_users"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $return[] = $row; } $existing_users=$return; //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"; } # add the output echo var_dump($return); echo "<br/>".$_POST['user_name']; ?>
<script language="javascript">
$(document).ready(function()
{
$("#username").blur(function()
{
$("#msgbox").removeClass().addClass('messagebox').text('Проверка...').fadeIn("slow");
$.post("scripts/user_availability.php",{ user_name:$(this).val() } ,function(data)
{
if(data=='no')
{
$("#msgbox").fadeTo(200,0.1,function()
{
$(this).html('Этот логин занят').addClass('messageboxerror').fadeTo(900,1);
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function()
{
$(this).html('Логин доступен для регистрации').addClass('messageboxok').fadeTo(900,1);
});
}
});
});
});
</script>