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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:23:24+00:00 2026-05-19T15:23:24+00:00

I have an update script that updates username, password, telephone,usergenerated id etc. So lets

  • 0

I have an update script that updates username, password, telephone,usergenerated id etc. So lets say a user decides to change his/her telephone but not the username. But when they go to edit their information, all of the above mentioned fields are present on the form. So the also get submitted along with what the user wants to have changed. So i am using the code below to detect that. So if the username in the field matches the username pulled from the session, it means its ok to continue, if not then print that the username is already taken. But the issue is that i have to run this query twice, once for the username and once for the unique id by the user. Further it gets complicated when the Update script is at the bottomo of the page. The codes below will detect it but they would stop at echo. So how do i make it so the code checks for those conditions and then upon successful completion it points to the update query.

Check 1:

if ($username == $_POST['username') {
  echo "Good to go";
} else {
  echo "already in use";
}

Check 2:

if ($usergenid == $_POST['usergenid') {
  echo "Good to go";
} else {
  echo "already in use";
}
  • 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-19T15:23:25+00:00Added an answer on May 19, 2026 at 3:23 pm

    maybe i’m misunderstanding the question, but can you nest your conditions?

    Original

    $result = null;
    
    if($username == $_POST['username']) 
    {
       if($usergenid == $_POST['usergenid'])
       {
    
          /* perform update to user */
          $sql = 'UPDATE users SET username = ' . $_POST['username'] . ' WHERE id = ' . $_POST['usergenid'];
          if(mysql_query($sql))
          {
             $result = 'User updated';
          }
          else
          { 
             $result = 'Update failed';
          }
    
       }
       else
       {
          $result = 'User id already in use';
       }
    } 
    else 
    {
      $result = 'Username already in use';
    }
    
    return $result;
    

    Update username if user_id matches

    $result = null;
    
    if($usergenid == $_POST['usergenid'])
    {
       if($username != $_POST['username']) 
       {
    
          /* perform update to user */
          $sql = 'UPDATE users SET username = ' . $_POST['username'] . ' WHERE id = ' . $_POST['usergenid'];
          if(mysql_query($sql))
          {
             $result = 'username updated';
          }
          else
          { 
             $result = 'update failed';
          }
    
       }
       else
       {
          $result = 'username is the same, no update performed';
       }
    } 
    else 
    {
      $result = 'user id does not match';
    }
    
    return $result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a PHP-script to update a web server that is live inside
I have the followign bash script to update mtimes for maildir files: #!/bin/bash for
I have an UPDATE sql command that modifies a Date/Time field in a particular
I have some update or something that tries to run every night, and ends
I have an update query being run by a cron task that's timing out.
I have several update methods in a javascript file, used for updating my ajax
I have to update old projects at work. I do not have any experience
Whenever we have to update the database; we delete the values from the table
The problem: I often have to update two or more repositories: One for the
Trying to do an insert, I have: jdbcTemplate.update(insert into...., new Object[]{foo.getId(), foo.getName()}) foo.getId() returns

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.