{"id":681,"date":"2011-01-05T11:04:22","date_gmt":"2011-01-05T16:04:22","guid":{"rendered":"http:\/\/it.thelibrarie.com\/weblog\/?p=681"},"modified":"2011-01-05T11:05:59","modified_gmt":"2011-01-05T16:05:59","slug":"error-in-sql-syntax","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2011\/01\/error-in-sql-syntax\/","title":{"rendered":"Error in SQL syntax"},"content":{"rendered":"<p>Man, I&#8217;m not very good at this PHP stuff in terms of starting from scratch.  I can decipher what is going on, but my troubleshooting skills for editing my own work&#8230; suck.<\/p>\n<p>I put up a survey site with very simple post of data into a mysql database from a PHP front-end.  My boss tried it out and put an apostrophe in his comments section, which threw up the standard:<br \/>\n<code>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 'm working hard')' at line 37<\/code><\/p>\n<p>Ut oh.  Showing SQL errors can lead to problems &#8211; injections, giving away data, etc.  Since this was an internal-only site, it didn&#8217;t really matter quite as much, but I&#8217;d still like to allow people to utilize the apostrophe.<\/p>\n<p>Add this into the inserting php page:<\/p>\n<blockquote>\n<pre> foreach ($_POST as $key =&gt; $value) {\r\n    $_POST[$key] = mysql_real_escape_string($value);\r\n  }<\/pre>\n<\/blockquote>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-682\" title=\"sqlsyntax\" src=\"http:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2011\/01\/sqlsyntax.png\" alt=\"\" width=\"438\" height=\"52\" srcset=\"https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2011\/01\/sqlsyntax.png 438w, https:\/\/it.thelibrarie.com\/weblog\/wp-content\/uploads\/2011\/01\/sqlsyntax-300x35.png 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/p>\n<p>It is right after my &#8220;mysql_select_db(&#8220;dbname&#8221;, $con); statement.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Man, I&#8217;m not very good at this PHP stuff in terms of starting from scratch. I can decipher what is going on, but my troubleshooting skills for editing my own work&#8230; suck. I put up a survey site with very simple post of data into a mysql database from a PHP front-end. My boss tried &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2011\/01\/error-in-sql-syntax\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Error in SQL syntax<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,1,5],"tags":[],"class_list":["post-681","post","type-post","status-publish","format-standard","hentry","category-linux","category-miscellaneous","category-troubleshooting"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=681"}],"version-history":[{"count":4,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/681\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/681\/revisions\/686"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}