Im trying to import a mysql table with data that has html code in it and it generates syntax error. Can someone tell me how to properly import mysql with html code
Sytanx error :
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 ''<ul>\r\n<li>Unpack the equipment and materials</li>\r\n<li>Secure the mounting '
By the very little you have shown us the error i can see that it's complaining about a rouge single quote '
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 ''<ul>\r\n<li>Unpack the equipment and materials</li>\r\n<li>Secure the mounting '
If you notice at the start of the quoted text from MySQL it has ''
and at the end it only has '
MySQL errors show the problem code at the start location in single quotes so we remove one single quote wrapping the errored syntax we end up with
'<ul>\r\n<li>Unpack the equipment and materials</li>\r\n<li>Secure the mounting
So it's complaining about a single quote before a <ul>
. you need to make sure you HTML is MySQL safe before entering it into the Database so replace single quotes as \'
or if it's supposed to be rendered you should use '
if your using php you can use addslashes
to escape any single quotes '
with \'
before entry.
Another option is to stop using directly constructed queries and use prepare & bind_param in your connector as it will then prevent this from happening.
Unfortunately, however, If you're using mysqlimport cli and this is a prebuilt .sql file your gonna have to go through it by hand and fix it I highly recommend a syntax enabled editor to do this MySQL workbench it the best for MySQL syntax