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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:17:03+00:00 2026-05-20T00:17:03+00:00

Ok I’m starting to spin out now. Too much trial and error has made

  • 0

Ok I’m starting to spin out now. Too much trial and error has made me rather grumpy.

I am trying to do an INSERT and UPDATE if EXISTS using a loop. I have excluded the loop code from this example to simplify my problem.

Here is the query in my PHP script:

function insertrating($ratingid, $rating){
    $link = resdb::connect();
    $r = mysqli_query($link, "INSERT INTO propertyrating (id,name)" 
                            ."VALUES (\'$ratingid\',\'$rating\')\n"
                ."ON DUPLICATE KEY UPDATE\n"
                ."name = VALUES (name),\n"
                ."description = VALUES (description)\n"
                . "");
    if($r > 0){
        return true;
    }
 }
 $mydbclass = new $dbclass();
 $mydbclass->insertrating('3','3 Star');

Table is as follows:
id int
name varchar(100)
description text

I do not want to add description at this stage. Hence no parameters for that column

I have produced the exact same query in phpMyAdmin and the MySQL console, both work. Thus im guessing its something to do with my syntax.

Also, if I get rid of the ON DUPLICATE KEY UPDATE function and parameters it works. However, obviously doesn’t update duplicate rows.

Please ask or correct where I am wrong. Thanks.

EDIT: REQUESTED SQL

INSERT INTO 
 propertyrating 
 (
   id,
   name
 ) 
VALUES 
 (
   '3',
   '3 Star'
 ) 
ON DUPLICATE KEY UPDATE
name = VALUES (name),
description = VALUES (description)

AS REQUESTED UNIQUE * PK

Table is as follows:

id int UNIQUE AND PRIMARY KEY
name varchar(100)
description text

OK GUYS ERROR RETURNED:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATEname = name,description = description

as you can see there is no space between UPDATE and name (it reads, UPDATEname) i added a character space and now all is gravy.

Many thanks for getting me to mysqli_error($link)

not sure how to give answer to zerkms but u all led me in the right direction, first.

Code now stands as:

$r = mysqli_query($link, "INSERT INTO propertyrating (id,name)" 
                        ."VALUES (\'$ratingid\',\'$rating\')\n"
            ."ON DUPLICATE KEY UPDATE\n"
            ."name = VALUES (name),\n"
            ."description = VALUES (description)\n"
            . "") or die("Error: ".mysqli_error($link));
  • 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-20T00:17:04+00:00Added an answer on May 20, 2026 at 12:17 am

    Put echo mysqli_error($link); right after mysqli_query to get the exact error happened (if any)

    But make sure you’ve removed this line after this debugging session.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.