Pacopag Posted August 17, 2011 Share Posted August 17, 2011 Hi. I'm having a problem that is making me hostile. All I'm trying to do is to write the result of $phpgetbrowser = mysql_real_escape_string(print_r(get_browser(null, true), true)); to a mysql table. The data type in the table I'm using is varchar(800). So I do $sql = "insert into browsers values ('".$phpgetbrowser."')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } What's making me crazy is that I copied and pasted this latter code from elsewhere in the script, where it works fine. I'm sure that the mysql connection has already been made, and that $phpgetbrowser is initialized. I get the following error 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 ''Array\n(\n [browser_name_regex] => ^mozilla/5\\.0 (.*linux x86_64.*) applewe' at line 1 Any help would make me a much happier man. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/244966-mysql-syntax-error/ Share on other sites More sharing options...
Clarkeez Posted August 17, 2011 Share Posted August 17, 2011 $phpgetbrowser is your problem, it's not a valid array. Try break down your functions you've used on the variable. Quote Link to comment https://forums.phpfreaks.com/topic/244966-mysql-syntax-error/#findComment-1258350 Share on other sites More sharing options...
Pacopag Posted August 17, 2011 Author Share Posted August 17, 2011 But I'm writing $phpgetbrowser to the same table in exactly the same way elsewhere in the script. It's the same 3 lines of code that works in one place but not another. Thanks for your reply. Quote Link to comment https://forums.phpfreaks.com/topic/244966-mysql-syntax-error/#findComment-1258353 Share on other sites More sharing options...
Clarkeez Posted August 17, 2011 Share Posted August 17, 2011 Ok, take away mysql_real_escape_string() and try again. Quote Link to comment https://forums.phpfreaks.com/topic/244966-mysql-syntax-error/#findComment-1258356 Share on other sites More sharing options...
Pacopag Posted August 17, 2011 Author Share Posted August 17, 2011 Good suggestion, but didn't work. It's never been clear to me when to use mysql_real_escape_string and when not to. I always figured I should apply whenever I'm writing a string to mysql tables. Quote Link to comment https://forums.phpfreaks.com/topic/244966-mysql-syntax-error/#findComment-1258363 Share on other sites More sharing options...
PFMaBiSmAd Posted August 17, 2011 Share Posted August 17, 2011 Your actual code must be doing something to the $phpgetbrowser variable in between where you are assinging the string to it and where you are using it in the query. Post all the code between and including the lines of code where you are assigning it and where you are using it in the query. The error message is indicating that you have an un-escaped single quote right before the word Array... Quote Link to comment https://forums.phpfreaks.com/topic/244966-mysql-syntax-error/#findComment-1258366 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.