Unusual error while entering data into the database

I just paste the data from the form using PHP into the MYSQL table, but I get an unusual error. My code

$q1="insert into product (category,image,name,desc) values ('$cat','$pname','$name','$desc')";
        $res1=$con->query($q1);
        if($res1)
        {
            some logic;
        }
        else
        {
            echo "error";
        }

I unusually get the else part executed, even if the code is sytactically correct.i checked and checked the values ​​of all the PHP variables. I use the OOP PHP style to connect to the database. Also, when executing a query in PHPmyadmin using random values ​​too, I get the following error:

SQL query:

INSERT INTO Product( category, image, name, DESC )
VALUES (
'dsdsd', 'sddsd', 'sd', 'it is a nice'
)

MySQL said: Documentation

#1064 - 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 'desc)
VALUES
('dsdsd','sddsd','sd','it is a nice')' at line 1 
+3
source share
3 answers

DESC is a reserved keyword to use backticks as

INSERT INTO Product( category, image, name, `DESC` )
+2
source

DESCIs the keyword in MySQL, you need to put this in the Back ticks ``

INSERT INTO Product( category, image, name, `DESC` )
VALUES (
'dsdsd', 'sddsd', 'sd', 'it is a nice'
)
+2
source

DESCis the mysql keyword. You need to use the reverse as follows: -

INSERT INTO Product( category, image, name, `DESC` )
+1
source

All Articles