{"id":18451391,"date":"2025-05-05T20:32:19","date_gmt":"2025-05-05T20:32:19","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/sql-syntax-errors-3\/"},"modified":"2025-05-05T20:32:19","modified_gmt":"2025-05-05T20:32:19","slug":"sql-syntax-errors-3","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/sql-syntax-errors-3\/","title":{"rendered":"SQL Syntax Errors"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">FormCraft v1.2.11, WP 6.8.1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Getting the following error when attempting to edit a form:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>[05-May-2025 20:05:08 UTC] WordPress database error 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 ''wpws_formcraft_b_forms' WHERE id = 5' at line 1 for query SELECT * FROM 'wpws_formcraft_b_forms' WHERE id = 5 made by do_action('toplevel_page_formcraft_basic_dashboard'), WP_Hook-&gt;do_action, WP_Hook-&gt;apply_filters, formcraft_basic_dashboard, require_once('\/plugins\/formcraft-form-builder\/views\/builder.php')<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;ve traced this to the following line in builder.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>$qry = $wpdb-&gt;get_results( $wpdb-&gt;prepare(\"SELECT * FROM %s WHERE id = %d\", $forms_table, $form_id));<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Preparing the statement in this fashion includes the table name as a single quoted string, which causes the error.  I&#8217;ve resolved this issue by updating the code:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>$qry = $wpdb-&gt;get_results( $wpdb-&gt;prepare(\"SELECT * FROM $forms_table WHERE id = %d\", $form_id));<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212;-<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There&#8217;s another syntax error in formcraft-main.php, line 473.  There&#8217;s an extra comma following the table name in the statement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Continuing to troubleshoot here and will fix these issues locally, but I hope that they can be addressed by a future update.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks!<\/p>\n","protected":false},"template":"","class_list":["post-18451391","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18451391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18451391\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18451391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}