Page 1 of 1

varchar and escaping

Posted: Thu Jun 06, 2002 5:19 pm
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

Posted: Fri Jun 07, 2002 2:38 am
by mikeq
Before outputing your variable use the StripSlashes() function.

$CorrectOutput = StripSlashes($WithApostrophe);

Posted: Fri Jun 07, 2002 5:44 am
by apljdi
:wink:

cool.

Thanks. I knew this had to be simple.

John