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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:33:23+00:00 2026-06-12T01:33:23+00:00

People I am trying to use the same script for approving a contact to

  • 0

People

I am trying to use the same script for approving a contact to be added to the database, but the query will do an update if the primary key (id) is already there. So i set up a INSERT INTO …. ON DUPLICATE KEY UPDATE query, which is below:

$resultsc = mysql_query("INSERT INTO $contact     (id,First,Last,Companyid,userid,Title,PrimaryPhone,SecondaryPhone,PrimaryEmail,SecondayEmail,inserted) VALUES('$id','$first','$last','$companyid','$userid','$title','$phone1','$phone2','$email1','$email2',NOW()) ON DUPLICATE KEY UPDATE (First,Last,Companyid,userid,Title,PrimaryPhone,SecondaryPhone,PrimaryEmail,SecondayEmail) VALUES ('$first','$last','$companyid','$userid','$title','$phone1','$phone2','$email1','$email2') WHERE id='$id'"); 

if(!$resultsc)
        {
            echo "<font face='Verdana' size='2' ><center>You have successfully approved this user for access to this site.</center><br><center><input type='button' value='Back' onClick='history.go(-2)'></center>"; die();
        }
else
    {

        echo "<font face='Verdana' size='2' ><center>You have not updated this contact for this site.</center><br><center><input type='button' value='Back' onClick='history.go(-2)'></center>";
    }

I am not getting any errors but the database is not updating or inserting a new record. So I checked my “$contacts” variable to ensure it is is pointing to the correct table, and it is. If i just do an insert alone then the script is working fine. But when i do this query nothing happens. I am wondering what is wrong with it or should i just have a if/else with a select checking for a existing key?

  • 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-12T01:33:24+00:00Added an answer on June 12, 2026 at 1:33 am

    The syntax is wrong.

    INSERT ... ON DUPLICATE KEY UPDATE
       field1=VALUES(field1),
       field2=field2+1,
       field3='fixevalue',
       field4=VALUES(field4)
       etc...
    

    Note the use of the values() function. It’s very handy in these on dupe querys, so you don’t have to insert the field’s value twice (once in the insert part, once in the update part). MySQL will simply use the value from the insert portion again in the update. Very handy if you’re inserting ‘large’ data and don’t want to waste bandwidth on duplicate data.

    On a metalevel, don’t output a fixed error messages as you are while in debugging phase:

    if (!$resultc) {
       die(mysql_error());
    }
    

    is far more useful and helpful than “oops, something didn’t work”.

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

Sidebar

Related Questions

I am trying to use .ajax() to post a People object to a MVC2
I'm learning pyramid and it seems they are trying to get people to use
I've looked at quite a few links for people trying to add content /
I am trying to list the people who have birthday this week with this
I am trying to convince some senior people at my company of the advantages
I'm trying to setup a system to minimize complexity for people updating the site
I trying to fix a strange bugg. People with IOS 4 can't even start
Hi I am trying to scrape other people web pages (for the forces of
I am trying to get the list of people from the http://en.wikipedia.org/wiki/Category:People_by_occupation . I
hey people I'm new at jquery and i have been trying to figure this

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.