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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:43:48+00:00 2026-05-30T10:43:48+00:00

my table(s) structure (MySQL / each one is same as below) +——-+————–+——+——+——————-+ | Field

  • 0

my table(s) structure (MySQL / each one is same as below)

+-------+--------------+------+------+-------------------+
| Field | Type         | Null | Key  | Default           |
+-------+--------------+------+------+-------------------+
| id    | int(11)      | NO   | PRI  | AUTO INCREMENT    | 
| lesson| varchar(255) | NO   |      | LESSON_NAME       | 
| exam  | char(50)     | NO   |UNIQUE| NO DEFAULT        |
| quest | text         | NO   |      | NO DEFAULT        |
| answer| text         | NO   |      | NO DEFAULT        |
| note  | text         | NO   |      | NO DEFAULT        |
+-------+--------------+------+------+-------------------+

and i’am posting some values to add this table via ajax ($post) – PHP 5.0
in database.php there is a function to get posted data and add to table

function update_table ($proper_table, $name, $question, $answer, $note) {
$sql = "INSERT INTO $proper_table (id, lesson, exam, quest, answer, note) VALUES ('', '', $name, $question,$answer,$note) ON DUPLICATE KEY UPDATE exam = $name, quest = $question, answer = $answer, note = $note";
$result= mysql_query($sql)or die(mysql_error());
}

$proper_table variable is taken by another variable to add this record to correct table.
(NOTE: Original table fields and variables are different (Turkish), to be more understandable i traslated to english but the syntax is the same as you see.)
Question : I want to check that if there is a record that exam field is same then all these variables will be used for updating this record, otherwise let function put this record to proper table as a new record.
But i’am getting error like below

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 

is there any faulty coding? and what can be the solution?
Thanks right now…

  • 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-30T10:43:49+00:00Added an answer on May 30, 2026 at 10:43 am
    function update_table ($proper_table, $name, $question, $answer, $note) {
        $sql = "INSERT INTO $proper_table (lesson, exam, quest, answer, note) VALUES ('', '$name', '$question','$answer','$note') ON DUPLICATE KEY UPDATE quest = VALUES(quest), answer = VALUES(answer), note = VALUES(note)";
       $result= mysql_query($sql)or die(mysql_error());
    }
    

    Just breaking this out I’ll detail the changes

    $sql = "INSERT INTO $proper_table 
    
    // Removed the PK (primary key) AI (auto increment) field - don't need to specify this
    (lesson, exam, quest, answer, note)     
    
    // Likewise removed PK field, and added quotes around the text fields
    VALUES ('', '$name', '$question','$answer','$note')    
    ON DUPLICATE KEY UPDATE 
    
    // If you specify VALUES(fieldName) it will update with the value you specified for the field in the conflicting row
    // Also removed the exam update, as exam is the UNIQUE key which could cause conflicts so updating that would have no effect
    quest = VALUES(quest), answer = VALUES(answer), note = VALUES(note)";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have the following MySQL table structure: num field company phone website 1 Gas
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
When retrieving a hierarchical structure from MySQL (table with one ID column and one
I have two MySQL databases with identical table structure, each populated with several thousand
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
This is the MySQL table structure that I have: itemID (BIGINT) userID (BIGINT) wasAdded
What's the best way to structure a MySQL table for storing admin settings? Like
Is it possible to somehow get structure of MySQL database, or just some table
I am using a MySQL table called login with the following structure: loginid, username,

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.