Kiraahmad
Kiraahmad

Reputation: 159

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax

I have an error whenever I try to test my endpoint for the database it says "code": "ER_PARSE_ERROR"

so this is my model for mysql database:

let query = `UPDATE tbl_branch_info 
            SET 
            ${whats === undefined ? `` : `whats=${whats},`}
            ${twitter === undefined ? `` : `twitter='${twitter}',`}
            ${facebook === undefined ? `` : `facebook='${facebook}',`}
            ${snapchat === undefined ? `` : `snapchat='${snapchat}',`}
            ${instagram === undefined ? `` : `instagram='${instagram}',`}
            ${phone === undefined ? `` : `telephone=${phone},`}
            ${address === undefined ? `` : `address='${address}',`}
            ${email === undefined ? `` : `email='${email}',`}
            ${city_id === undefined ? `` : `city_id=${city_id},`}
            ${category_id === undefined ? `` : `category_id=${category_id},`}
            ${subCategoryId === undefined ? `` : `sub_cat_id=${subCategoryId},`}
            ${lon === undefined ? `` : `lon=${lon},`}
            ${lat === undefined ? `` : `lat=${lat}`}     
            WHERE branch_id = ${branch_id}`;

it gives me this error :

error message from postman

but then if I change the last line before the the branch_id which is the lat to this

lat='${lat}'

it will pass data just fine, so what could be the problem here ?

Upvotes: 1

Views: 1174

Answers (1)

Akina
Akina

Reputation: 42728

let query = `UPDATE tbl_branch_info 
            SET 
            ${whats === undefined ? `` : `whats=${whats},`}
            ${twitter === undefined ? `` : `twitter='${twitter}',`}
            ${facebook === undefined ? `` : `facebook='${facebook}',`}
            ${snapchat === undefined ? `` : `snapchat='${snapchat}',`}
            ${instagram === undefined ? `` : `instagram='${instagram}',`}
            ${phone === undefined ? `` : `telephone=${phone},`}
            ${address === undefined ? `` : `address='${address}',`}
            ${email === undefined ? `` : `email='${email}',`}
            ${city_id === undefined ? `` : `city_id=${city_id},`}
            ${category_id === undefined ? `` : `category_id=${category_id},`}
            ${subCategoryId === undefined ? `` : `sub_cat_id=${subCategoryId},`}
            ${lon === undefined ? `` : `lon=${lon},`}
            ${lat === undefined ? `` : `lat=${lat},`}    
            ${`branch_id = ${branch_id}`} 
            WHERE branch_id = ${branch_id}`;

Upvotes: 1

Related Questions