Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8441885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:41:29+00:00 2026-06-10T08:41:29+00:00

I am learning something new with checking for whether a username is used in

  • 0

I am learning something new with checking for whether a username is used in the database and have created some code based on a tutorial I found online. I understand the logic, though not sure I have approached it the right way. In essence. Information is passed over from a form field. If what has been entered matches a field in the database then I want it to return / echo a result ‘yes’. if it does not match, I need it to echo ‘no’. Seems straight forward.

The tutorial is designed for predetermined values. i.e.
$existing_users=array(‘test’,”one’,’two’,three’);

Though I want the ‘test’,”one’,’two’,three’ to actually pull dynamically from a database.

So I went about adding the setting it up to do so, though the code I have written doesn’t work when I try to place dynamic values in. My code is as below:

$existing_users = array();
mysql_select_db($database_db, $db);
$result = mysql_query('SELECT * FROM clients') or exit(mysql_error());
while ($row = mysql_fetch_assoc($result)) {$existing_users[] = $row['shortcode'];}

$arr = $existing_users;

$display = "'" . implode("', '", $arr) . "'";

    // THIS IS THE PROBLEM 
    // If the code is written out as:
    // $existing_users=array('test',''one','two',three'); 
    // It works.
    // When the script is coded as below. It doesn't work.
    // Note. If I echo $display is displays 'test',''one','two',three'

$existing_users=array($display);

//value received from the get method
$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 available
echo "no";
} 
else
{ 
//user name is available 
echo "yes";
}

I am not sure whether I am approaching this the right way because I am hacking an online tute, there potentially could be a far easier way. Any thoughts would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:41:31+00:00Added an answer on June 10, 2026 at 8:41 am

    here’s a faster way to do it:

    $user_name=mysqli_real_escape_string($_POST['user_name']);
    
    $result = mysql_query("SELECT * FROM clients where shortcode like '$user_name'") or exit(mysql_error());
    
    if(mysql_num_rows($result)==0)
        echo 'no';
    else
        echo 'yes'
    

    i didnt validate the input from $_POST tho

    what tutorial are you following anyway??

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning AJAX and created this simple code. I type in something in the
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
This question is something that a lot of people learning bioinformatics and new to
I'm learning asp.net mvc and found something interesting: It seems that I can't explicitly
There is something I can't digest. I'm learning some assembler and right now I'm
I'm learning about references and pointers, and something in the tutorial isn't compiling for
I'm new to Qt and I'm learning something new every day. Currently, I'm developing
Learning rails and something smells a little funny. I have the following form for
Something I don't enjoy about programming is learning a new API. For example, right
I'm new to Objective-c. For learning purposes I'm trying to build something like a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.