Click here to Skip to main content
15,035,685 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my update query cant worked
<pre>Actually I doing a crud operation. I completed insert, select and delete also.
But when write a update query in my update.php file, it cant worked.
so, I echo my query and paste into database(localhost/phpmyadmin).
after that they give me this type of error->"<pre>You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''product_details' SET 'name'='saumil joshi','category'='mobile phone','brand'...' at line 1
"
so,what sholud i do now?
anybody can hear to solve this problem?

What I have tried:

Actually I doing a crud operation. I completed insert, select and delete also.
But when write a update query in my update.php file, it cant worked.
so, I echo my query and paste into database(localhost/phpmyadmin).
after that they give me this type of error->"<pre>You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''product_details' SET 'name'='saumil joshi','category'='mobile phone','brand'...' at line 1
"
so,what sholud i do now?
anybody can hear to solve this problem?
Posted
Updated 2-Jun-21 22:25pm
Comments
Patrice T 3-Jun-21 4:50am
   
And you plan to show the code ?

1 solution

We can't help you: we have no access to the code you are using, and that's going to be pretty significant to the problem.

So start by looking at the line of code that is executing when that error is thrown: use the PHP Debugger[^] to find out exactly what the command you are sending to the DB.

More often than not, this is caused by either a simple mistyping in your code, or by SQL injection prone code. Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900