Forum Moderators: coopster

Message Too Old, No Replies

dealing with escape characters and mysql

         

jackvull

12:31 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



Hi
I am trying to put the following text into my DB but mySQL keeps rejecting it as the character is invalid.
The character is ;
which has obvious problems.
I have tried escaping it with \; but doesn't work either.
Any ideas?

It's for putting things i a databse like HTML chars such as   or Å

Thanks

tomda

12:39 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use htmlentities() or htmlspecialchars() before inserting data in the database. Do some search for those two functions to get some basic example on how it works.
It is a MUST to check your data and replace special string before insertion in Mysql.

jackvull

12:51 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



but won't htmlentities just replace special characters with the html equivalent e.g. & to "

The problem I have is that MySQl sees the ; and thinks that it has come to the end of the statement even though I want to actually insert the ; into the database

tomda

1:12 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Indeed, it does! And ; is not a special character. Never realised because I never had problems with ; character.

I just tried it now and no error... All fine!

Can you post your query so that we have a look at it.

henry0

1:20 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Easy integration through a concat
ex:
$start="aa";
$end=";";

$total=$start.$end;

result:

echo"$total";

will read
aa;

jc_armor

1:48 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



try using addslashes :)

jatar_k

5:49 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if your mysql is interpretting ; as end of line then you probably have a quote mismatch somewhere.