petenetman Posted January 30, 2008 Share Posted January 30, 2008 Say I have: $vSQL .= "Message=" . chr(34) . $Message . chr(34) . and the $Message contains \\myserver\inetpub\www\ When I post to MySql I get \myserverinetpubwww I have no idea why. I know the chr(34) takes out the single quotes around text in the $Message. All I want to do is to post to MySql whatever is in the text field. Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/ Share on other sites More sharing options...
trq Posted January 30, 2008 Share Posted January 30, 2008 Take a look at mysql_real_escape_string(). Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453284 Share on other sites More sharing options...
petenetman Posted January 30, 2008 Author Share Posted January 30, 2008 I must be having a little 'Thicko' day - Sorry Let me explain a little better.... This code is as follows: if ( $JobNo > 0) { $vSQL = "UPDATE worklog SET RepBy='" . $RepBy . "', Contact='" . $Contact . "', "; $vSQL .= "Message=" . chr(34) . $Message . chr(34) . ", Handled='" . $Handled . "', Detail=" . chr(34) . $Detail . chr(34) . ", "; $vSQL .= "CompletedIT='" . $CompletedIT . "', Priority='" . $Priority . "', JobGroup='" . $JobGrp . "' , "; $vSQL .= "CatType='" . $CatType . "', CatDate='" . $CatDate . "' "; $vSQL .= "WHERE JobNo=" . $JobNo; The $Message field and the $Detail field can contain any text character. After moving from a UNIX box to windows I had to change the $message to chr(34) as MySql fell over the something like 'ReadMe' as used in the test field. I am trying to find a string that goes around both $fields so MySql can handle the update. Thanks Pete Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453296 Share on other sites More sharing options...
trq Posted January 30, 2008 Share Posted January 30, 2008 Did you look at the link I posted? Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453299 Share on other sites More sharing options...
petenetman Posted January 30, 2008 Author Share Posted January 30, 2008 Yes I did, but couldn't find a piece of code I could use to place either side of my 2 fields without having to rewrite the complete statement. Pete Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453300 Share on other sites More sharing options...
trq Posted January 30, 2008 Share Posted January 30, 2008 if ( $JobNo > 0) { $Message = mysql_real_escape_string($Message); $Detail = mysql_real_escape_string($Detail); $vSQL = "UPDATE worklog SET RepBy='" . $RepBy . "', Contact='" . $Contact . "', "; $vSQL .= "Message=" . chr(34) . $Message . chr(34) . ", Handled='" . $Handled . "', Detail=" . chr(34) . $Detail . chr(34) . ", "; $vSQL .= "CompletedIT='" . $CompletedIT . "', Priority='" . $Priority . "', JobGroup='" . $JobGrp . "' , "; $vSQL .= "CatType='" . $CatType . "', CatDate='" . $CatDate . "' "; $vSQL .= "WHERE JobNo=" . $JobNo; Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453305 Share on other sites More sharing options...
petenetman Posted January 30, 2008 Author Share Posted January 30, 2008 I'm afraid $Message = mysql_real_escape_string($Message); $Detail = mysql_real_escape_string($Detail); Did not help. Neither did it stop my page from working. Would it be something to do with the version of PHP that I've got installed? It's v4 Pete Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453344 Share on other sites More sharing options...
chum Posted January 30, 2008 Share Posted January 30, 2008 mostly likely yes, mysql_real_escape_string function is relatively new, Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453346 Share on other sites More sharing options...
petenetman Posted January 30, 2008 Author Share Posted January 30, 2008 Surly there must be a way to send any type of characters to a MySql table field? ??? Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453351 Share on other sites More sharing options...
petenetman Posted January 30, 2008 Author Share Posted January 30, 2008 Is it quite easy to upgrade from PHP v4 to V5? Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453464 Share on other sites More sharing options...
trq Posted January 30, 2008 Share Posted January 30, 2008 If you dont have mysql_real_escape_string() you can use addslashes in this case. Is it quite easy to upgrade from PHP v4 to V5? Depends on your OS really but yeah, Id'e recommend it. php4 is no longer supported by the php devs. Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-453468 Share on other sites More sharing options...
petenetman Posted January 31, 2008 Author Share Posted January 31, 2008 Thanks for that... I can't use the add slashes in this case bacuses anything can be placed in the $message field i.e. [Hello this 'is' my name] or [web sever address \\myserver\inetpub\www] Quote Link to comment https://forums.phpfreaks.com/topic/88546-loosing-characters-when-posting-to-mysql/#findComment-454201 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.