varchar and escaping

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
apljdi
Forum Newbie
Posts: 2
Joined: Thu Jun 06, 2002 5:19 pm

varchar and escaping

Post by apljdi »

:roll:

Hi,

I have a MySQL table from which I am pulling data (varchar) and inserting it into a variable(PHP).

the relevant code looks like this:

$sub_query = "SELECT * FROM <table name> where ($order = '$main_sort'); $order is set earlier in the script
$sub_result = mysql_query(sub_query);

# the following is where it breaks

if (mysql_num_rows(sub_result)>0)
{
stuff here
}

It all works fine unless there is an apostrophe in the varchar data which is retrieved into sub_query. And I can't manage to escape the apostrophe. I've tried everything in the manual that I can find, but all of the characters print. It works but I end up with something like "Beckie''s Fanny' printing to the html output. If I eliminate the apostrophe the problem goes away.

Thanks

John
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Before outputing your variable use the StripSlashes() function.

$CorrectOutput = StripSlashes($WithApostrophe);
apljdi
Forum Newbie
Posts: 2
Joined: Thu Jun 06, 2002 5:19 pm

Post by apljdi »

:wink:

cool.

Thanks. I knew this had to be simple.

John
Post Reply