SQL error while adding record (Insert query)

QuestionsSQL error while adding record (Insert query)
Shivraj asked 10 years ago

I am getting below error while adding new record in DB

"Couldn't execute query. 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 '(`composition_pk`,`composition_title`) VALUES ('55','This is test')' at line 1 – INSERT INTO (`composition_pk`,`composition_title`) VALUES ('55','This is test')"

I get this error when I display specicific columns & try to insert record.
If I display whole table instead of setting columns, it works fine.
Here is code of columns:
$col = array();
$col["title"] = "composition_pk";
$col["name"] = "composition_pk";
$col["hidden"] = false;
$col["editable"] = true;
$col["autoid"] = true;
$cols[] = $col;

$col = array();
$col["title"] = "composition_title";
$col["name"] = "composition_title";
$col["width"] = "10";
$col["hidden"] = false;
$col["editable"] = true;
$cols[] = $col;

I found similar question by many users, most of the time, it occurs due to user error, but I am unable to point out my error.

Could you please help me.

4 Answers
Shivraj answered 10 years ago

My problem is solved, it is necessary to set table even if you are using table name in "SELECT" query.

$g->table = "table_name"; (this statement was missing, which was causing problem)
$g->select_command = "SELECT * FROM table_name";

Abu Ghufran answered 10 years ago

I was about to tell you same.
Glad to know it's resolved.

Alec Clarke answered 9 years ago

What if it is a multi-table SELECT? Do you just arbitrarily use the first table in the SELECT? Thanks

Abu Ghufran answered 9 years ago

It makes columns based on select query. For insert/update/update … you will need to use custom callback functions.
Refer demos/editing/custom-events.php

Your Answer

12 + 6 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?