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

  • Home
  • SEARCH
  • 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 195201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:39:38+00:00 2026-05-11T16:39:38+00:00

I have the following prepared query I am using with mysql and php. It

  • 0

I have the following prepared query I am using with mysql and php. It is to allow users to be added to a particular category, passed in via $subcat.

$alterQuery = "UPDATE AUCTIONS SET subcat= ? WHERE article_no= ?";
   if ($altRecord = $con->prepare($alterQuery)) {
       $altRecord->bind_param("ss", $subcat, $pk);
       $altRecord->execute();
    $altRecord->close();
    echo "true";
    }

What I would like to do, in the same query, is insert a new record in the USERS table only inserting the username, after checking that the username does not already exist. Is it possible just to change $alterQuery to:

What is the best what to do this?

Check for the username, and if it == null, do a subsequent insert? can I have two different queries executed in the same if block?

edit: attaching database scheme in response to comment

AUCTIONS    

    ARTICLE_NO      varchar(20) primary key
    ARTICLE_NAME    varchar(100)
    SUBTITLE    varchar(20)
    CURRENT_BID     decimal(5,2)
    START_PRICE     decimal(5,2)
    BID_COUNT   varchar(20)
    QUANT_TOTAL     varchar(20)
    QUANT_SOLD  varchar(20)
    ACCESSSTARTS    varchar(30)
    ACCESSENDS  varchar(20)
    ACCESSORIGIN_END    varchar(20)
    USERNAME    varchar(20)     
    BEST_BIDDER_ID  varchar(20)     
    FINISHED    tinyint(4)  
    WATCH   tinyint(4)      
    BUYITNOW_PRICE  decimal(5,2)    
    PIC_URL     varchar(120)    
    PRIVATE_AUCTION     tinyint(4)
    AUCTION_TYPE    varchar(20)     
    ACCESSINSERT_DATE   varchar(20)
    ACCESSUPDATE_DATE   varchar(20)
    CAT_DESC    varchar(20)     
    CAT_PATH    varchar(20)     
    ARTICLE_DESC    text    
    COUNTRYCODE     varchar(20)
    LOCATION    varchar(20)
    CONDITIONS  varchar(20)
    REVISED     tinyint(4) 
    PAYPAL_ACCEPT   tinyint(4) 
    PRE_TERMINATED  tinyint(4) 
    SHIPPING_TO     varchar(20)
    FEE_INSERTION   decimal(5,2)
    FEE_FINAL   decimal(5,2)
    FEE_LISTING     decimal(5,2)
    PIC_XXL     tinyint(4) 
    PIC_DIASHOW     tinyint(4) 
    PIC_COUNT   varchar(20)
    ITEM_SITE_ID    varchar(20)
    STARTS  datetime    
    ENDS    datetime    
    ORIGIN_END  datetime
    SUBCAT  varchar(20)

USERS
    username    varchar(30) primary key
    firstname   varchar(30)
    lastname    varchar(30)
    flaggedauctions     varchar(30)
    lastauction     varchar(30)     
    street1     varchar(30)     
    city1   varchar(30)     
    postcode1   varchar(30)
    street2     varchar(30)
    city2   varchar(30)     
    postcode2   varchar(30)
    phone   varchar(30)     
    mobilephone     varchar(30) 
    fax     varchar(30)     
    email   varchar(30)     
    website     varchar(30) 
    bank    varchar(30)     
    banknumber  varchar(30)
    accountnumber   varchar(30)
    comments    varchar(30)
  • 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-11T16:39:39+00:00Added an answer on May 11, 2026 at 4:39 pm

    It will be best to create a stored procedure:

    DELIMITER $$
    CREATE PROCEDURE prc_add_user_to_category(_subcat VARCHAR(20), _article_no VARCHAR(20), _username VARCHAR(30))
    BEGIN
            UPDATE  AUCTIONS
            SET     subcat= _subcat
            WHERE   article_no= _article_no;
            INSERT
            INTO    users (username)
            VALUES  (_username)
            ON DUPLICATE KEY
            UPDATE
            username = username;
    END
    $$
    DELIMITER ;
    

    and call it from your code:

    $alterQuery = "CALL prc_add_user_to_category(?, ?, ?)";
       if ($altRecord = $con->prepare($alterQuery)) {
           $altRecord->bind_param("ss", $subcat, $pk, $userid);
           $altRecord->execute();
        $altRecord->close();
        echo "true";
        }
    

    Checked and proved to compile and work against your schema on 5.2.0-falcon-alpha-community-nt-log

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

Sidebar

Ask A Question

Stats

  • Questions 152k
  • Answers 152k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Anonymous access to Reporting Services isn't recommended, although if you're… May 12, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer I meant "there is an empty table with no cols… May 12, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer This behavior is a non conformance in VC++6.0, you should… May 12, 2026 at 10:06 am

Related Questions

I have a form, the purpose of which is to place the currently displayed
I have a mostly desktop programming background. In my spare time I dabble in
I have a process in a website (Asp.net 3.5 using Linq-to-Sql for data access)
Environment I'm working on a C++ application that uses SQL Native Client 9.0 to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.