在将数据插入MySql
数据库时出错。
数据已成功插入,但出现错误[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] '
以下用于在数据库中插入记录的查询。
$sqldata = $wpdb->query("INSERT INTO `wp_make_details`
(`c_id`, `post_id`, `make_name`, `year`, `model_name`)
values (NULL,".$post_id.",'".$all_make."', '".$all_year."', '". $all_model."')");
回显查询结果,其值为
INSERT INTO `wp_make_details` (`c_id`, `post_id`, `make_name`, `year`, `model_name`) values (NULL,'15904','Yamaha', '2006', 'Stratoliner, Stratoliner S, Stratoliner Midnight, Roadliner, Roadliner S , Roadliner Midnight, Road Star, Road Star Midnight, Road Star Silverado, Road Star Midnight Silverado, V-Star 650 Custom, V-Star 650 Midnight Custom, V-Star 650 Classic, V-Star 650 Silverado, V-Star 1100 Custom, V-Star 1100 Midnight Custom , V-Star 1100 Classic, V-Star 1100 Silverado, Road Star Warrior, Road Star Midnight Warrior, V-Max, Virago 250, Royal Star Venture, Royal Star Midnight Venture , Royal Star Tour Deluxe, FJR1300A, FJR1300AE, YZF600R, YZF-R1, YZF-R1 50th Anniversary Edition, YZF-R1 LE, YZF-R1 LE, YZF-R6, YZF-R6 50th Anniversary Edition, YZF-R6S, MT-01 , XJR1300 , FZ1, FZ1 Naked, FZ6 , MT-03 , XT225, TW200, YZ450F, YZ450F 50th Anniversary Edition, YZ250 , YZ250F, YZ250F 50th Anniversary Edition, YZ125 , YZ85 , WR450F, WR250F, TT-R250, TT-R230 , TT-R125LE , TT-R125L , TT-R125E , TT-R125, TT-R90E, TT-R90 , TT-R50E , PW80 , PW50, Majesty, Morphous, Vino, Vino 125, BW's, X-Max 125 ')
我不知道发生了什么也不知道为什么MariaDB
会出现错误,我在谷歌中找到了但我无法得到解决方案。
有人知道它对我有帮助吗?
答案 0 :(得分:1)
最后我解决了这个问题,我错过了mysql_real_escape_string()
并使用此完成的查询
$sqldata = $wpdb->query("INSERT INTO `wp_make_details`
(`c_id`, `post_id`, `make_name`, `year`, `model_name`)
values (NULL,".$post_id.",'".$all_make."', '".$all_year."', '".mysql_real_escape_string($all_model)."')");
现在工作正常。