9three Posted February 14, 2009 Share Posted February 14, 2009 I'm grabbing the user agent from each user and inserting them into a database. Example: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 The problem is that user agent separates each line by semicolons so it makes my query not work properly. Any way to fix that? Quote Link to comment https://forums.phpfreaks.com/topic/145175-solved-http_user_agent-creating-invalid-query/ Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 INSERT INTO table (useragent) VALUES ('$useragent'); Escape $useragent with a function like mysql_real_escape_string. Quote Link to comment https://forums.phpfreaks.com/topic/145175-solved-http_user_agent-creating-invalid-query/#findComment-761967 Share on other sites More sharing options...
9three Posted February 14, 2009 Author Share Posted February 14, 2009 Oh is that it? Thought it was something else. hehe thanks. Quote Link to comment https://forums.phpfreaks.com/topic/145175-solved-http_user_agent-creating-invalid-query/#findComment-762280 Share on other sites More sharing options...
9three Posted February 14, 2009 Author Share Posted February 14, 2009 hmm... It's not working :/ Quote Link to comment https://forums.phpfreaks.com/topic/145175-solved-http_user_agent-creating-invalid-query/#findComment-762281 Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 How doesn't it work? Saying that it "doesn't work" doesn't help very much. What does your code look like? What errors do you get? etc. Quote Link to comment https://forums.phpfreaks.com/topic/145175-solved-http_user_agent-creating-invalid-query/#findComment-762284 Share on other sites More sharing options...
9three Posted February 14, 2009 Author Share Posted February 14, 2009 SQL query: INSERT INTO user_input (Name, Email, Date, Time, IP, Agent, Message) VALUES (My Name, [email protected], February 14, 2009, 6:05 PM, 127.0.0.1, Mozilla/5.0 (Windows; This is after sanitizing with mysql_real_escape_string. Also throws an exception, and I figured out it was with the Agent Fatal error: Uncaught exception 'Exception' with message '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 'name, [email protected], February 14, 2009, 6:05 PM, 127.0.0.1, Moz' at line 4' in C:\Users\9three\Desktop\Server\htdocs\gb\library\mysql.class.php:38 Stack trace: #0 C:\Users\9three\Desktop\Server\htdocs\gb\index.php(56): mysql->query('INSERT INTO use...') #1 {main} thrown in C:\Users\9three\Desktop\Server\htdocs\gb\library\mysql.class.php on line 38 Quote Link to comment https://forums.phpfreaks.com/topic/145175-solved-http_user_agent-creating-invalid-query/#findComment-762289 Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 You need to put quotes around your values. Quote Link to comment https://forums.phpfreaks.com/topic/145175-solved-http_user_agent-creating-invalid-query/#findComment-762298 Share on other sites More sharing options...
9three Posted February 14, 2009 Author Share Posted February 14, 2009 AH HA! of course. Quote Link to comment https://forums.phpfreaks.com/topic/145175-solved-http_user_agent-creating-invalid-query/#findComment-762302 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.