Happy New Year everybody... I have moved my notice board from a server running php 3 and mysql 3 to a server running php 5 and mysql 5. On the old server, if somebody wrote " it's mine" it would accept it into the database. On the new server, if somebody wrote "it's mine" the database won't accept it. They have to write "it\'s mine". The user won't get round this. How can I get round it? Regards, John C
Hi dsdf... Many thanks for your quick reply. However, I'm quite new to php so I don't fully understand. Can you give me some more guidance. I place a notice: It's me.This is the response: Error in executing INSERT INTO epals (id,reference,realname,email,city,country,days,interests,age,gender,type,remoteip,postdate,enddate,end,status)VALUES ('','2592','wecfwe','wefe','efcwe','wefwe','90','It's me','45 to 55','Male','ep','88.97.199.150','Monday 3rd of January 2011 at 13:59:57','03rd April 2011','04/03/2011','') query error:1064 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 's me','45 to 55','Male','ep','88.97.199.150','Monday 3rd of January 2011 at 13:5' at line 1 Can you understand this ?? Cheers, John C
I recommend you to build a function and add mysql_real_escape_string($string) on there. For example: function change_string($string) { return mysql_real_escape_string($string); } $interest = change_string("it's me"); $command = "INSERT INTO epals (id,reference,realname,email,city,country,days,interests,age,gender,type,remoteip,postdate,enddate,end,status)VALUES ('','2592','wecfwe','wefe','efcwe','wefwe','90',$interest,'45 to 55','Male','ep','88.97.199.150','Monday 3rd of January 2011 at 13:59:57','03rd April 2011','04/03/2011','');
what about this snippet function _clean($str){ return is_array($str) ? array_map('_clean', $str) : str_replace('\\', '\\\\', htmlspecialchars( (get_magic_quotes_gpc() ? stripslashes($str) : $str), ENT_QUOTES)); } PHP: : source: http://www.jooria.com/snippets?snippet=123 Code (markup):
Hi Guys... Many thanks for your suggestions. I've messed about all afternoon without success. However, I took a look in php.ini file and TURNED ON magic_quotes_gpc = On This solved the problem for me. Thanks for trying to help. I appreciate it. Kind regards John C
you can use the addslashes() stripslashes() functions to make sure things are escaped and not escaped correctly.
Hi tprinty... Thanks for your advice. Unfortunately I'm not too good at programming so I tend to take the easy way out.