We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32792
    • 30 Posts
    У меня есть форма регистрации сделанная на weblogin , и поле логин которое мне нужно проверять на лету на доступность свободного логина в базе! и есть вот такой код

    <?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";
    }
    ?>
    


    $existing_users=array(’Что мне сюда вписать? , чтобы получить массив пользователей зарегистрированных’);
      • 26744
      • 157 Posts
      $sql="SELECT username FROM modx_web_users";
      $result=mysql_query($sql);
      while($row=mysql_fetch_array($result)) {
      $return[] = $row;
      }
      $return будет содержать массив имен пользователей/

      Это без API Modx, т.к. проще и быстрее.
        • 32792
        • 30 Posts
        Чет я туплю, но куда вставить эту конструкцию для приведенного когда?
          • 26744
          • 157 Posts
          <?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";
          }
          ?>
            • 32792
            • 30 Posts
            Quote from: sergil at Jun 21, 2011, 03:56 AM

            <?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";
            }
            ?>


            пробовал так но не работает от чего то! и таблица есть modx_web_users и поле username (
              • 26744
              • 157 Posts
              упс - ошибка
              $existing_users=$return[];
              нужно
              $existing_users=$return;
              Работает
                • 32792
                • 30 Posts
                Quote from: sergil at Jun 21, 2011, 04:26 AM

                упс - ошибка
                $existing_users=$return[];
                нужно
                $existing_users=$return;
                Работает
                нет все равно без результатов!
                  • 26744
                  • 157 Posts
                  Так. Попробуем потестировать.
                  <?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'];
                  ?>
                    • 32792
                    • 30 Posts
                    Quote from: sergil at Jun 21, 2011, 04:42 AM

                    Так. Попробуем потестировать.
                    <?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>
                    


                    где user_availability.php как раз наш вызов из базы!
                      • 26744
                      • 157 Posts
                      А сниппет то куда вставляешь? wink
                      Дополнительно приведенный тобой код - это javascript,который отображает результат работы сниппета.

                      А PHP-кусок у тебя идет отдельным файлом? Тогда не хватает данных базы и соединения с БД