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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:23:15+00:00 2026-06-03T03:23:15+00:00

I have an IF NOT EXISTS statement. IF it doesn’t exist an INSERT statement

  • 0

I have an IF NOT EXISTS statement. IF it doesn’t exist an INSERT statement follows. IF EXISTS I need to understand what is/can be returned so that I can interpret it with PHP.

so:

IF NOT EXISTS (SELECT id FROM users WHERE lname='SMITH')
INSERT INTO users (lname='SMITH')

I thought that the negative would return no result so could use a standard

if ($result){echo "record added";}
else {echo "duplicate - no record added";}

But that’s not what’s happening and I’m not sure how to achieve what I need – any suggestions?

Thank you for your kind attention.

  • 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-03T03:23:16+00:00Added an answer on June 3, 2026 at 3:23 am

    In both cases $result would return the response for a successfully run command and nothing more. INSERT doesn’t yield any rows, and neither does an IF statement that doesn’t have a matching condition.

    You can use SELECT SCOPE_IDENTITY() if you want to retrieve the inserted ID, and then you can check if $result has returned a row.

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

Sidebar

Related Questions

i have 2 tables CREATE TABLE if not exists tag_name( + tagid INTEGER PRIMARY
I have the following table: CREATE TABLE IF NOT EXISTS `customer_list` ( `id` INT
I have a code: CREATE TABLE IF NOT EXISTS Person ( name varchar(24) ...
I have this table: CREATE TABLE IF NOT EXISTS `produtos` ( `id` int(11) NOT
Paramiko's SFTPClient apparently does not have an exists method. This is my current implementation:
I have 2 tables in my mysql database: CREATE TABLE IF NOT EXISTS `RECIPES`
i have a signup page and i want to check username exists or not
TTreeNode does not have a Visible property, so the obvious option does not exist.
I have often PATHs for files which do not exist in my codes. I
I have an array and variable. If the variable does not exist in 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.