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 5935663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:17:13+00:00 2026-05-22T15:17:13+00:00

I’ve been learnging php/mysql for a short while and I got some basic stuff

  • 0

I’ve been learnging php/mysql for a short while and I got some basic stuff working that allowed me to make a chat server.

Can create the DB, post a message, retrieve new messages.

I’ve hit a brickwall now while trying to create a script to allow usernames to be created.
There are not passwords involved in this. 3 steps involved in this i think.

  1. The user submits a username to the server along with there Unique ID and if the name doest exist, then I add the name and there uid to the DB and the name belongs to that uid and nobody else can take it and I echo ‘Success’ back to the client.
  2. If they submit a name thats already there in the DB, but the clients uid matchs the uid associated to the name in the DB, then i just echo back ‘Success’. no need to add anything to the DB.
  3. They submit a name and uid to the DB, the name is already taken and the uid associated with that name in the DB does not match with this clients uid so i echo back ‘Fail’ to the client.

This is what I’ve done so far in my script. I added in pseudo code for where I dont yet understand how to create the necessary logic.

<?php
// put_score.php
/** MySQL database name */
define('DB_NAME', 'db_Chat');
/** MySQL database username */
define('DB_USER', 'chat_App');
/** MySQL database password */
define('DB_PASSWORD', 'smile123');
/** MySQL hostname */
define('DB_HOST', $_ENV{DATABASE_SERVER});

$table = "ab_username";

// Initialization
$conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);

// Error checking
if(!$conn) {
    die('Could not connect ' . mysql_error());
}

if($_GET['secret'] != "some_secret") {
    die('Nothing to see here...');
}

// Localize the GET variables
$udid   = isset($_GET['udid']) ? $_GET['udid'] : "";
$name   = isset($_GET['name']) ? $_GET['name']  : "";


// Protect against sql injections
$udid  = mysql_real_escape_string($udid);
$name  = mysql_real_escape_string($name);

if username exists in the DB
{
    if the UID associated with that username in the database matchs the UID submited by the client the echo 'Success'
    else echo 'Fail'
}
else // add name and UID to database echo 'Success'
{

// Insert the username
$retval = mysql_query("INSERT INTO $table(
        udid,
        name
    ) VALUES (
        '$udid',
        '$name'
    )",$conn);

if($retval) {
    echo "Success";
} else {
    echo "Fail";
}
 }
mysql_close($conn);

?>

If anybody could help me get the replace the pseudo code it would be very much appreciated.

Many Thanks,
-Code

  • 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-05-22T15:17:14+00:00Added an answer on May 22, 2026 at 3:17 pm

    Can’t test this currently, but this is pretty much what you need:

    $udid_mismatch=false;
    $name_found=false;
    $result = mysql_query("SELECT udid FROM table WHERE name='$name'");
    while( $row = mysql_fetch_assoc($result) ){
        $name_found=true;
        if($row['udid'] != $udid){
            $udid_mismatch=true;
        }
        break;
    }
    
    if($name_found && $udid_mismatch ){
        echo 'Fail';
    } else if($name_found) {
        echo 'Success';
    } else {
        //Insert the username
    }
    

    Be sure to replace “table” in the query with your correct table name.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have some data like this: 1 2 3 4 5 9 2 6
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.