Forum Moderators: coopster

Message Too Old, No Replies

Escaping characters

         

implemens

8:39 pm on May 6, 2004 (gmt 0)




Hi, my first message here...

I'm trying to add a row to a MySQL table via a PHP script. The problem is that one field, of type TEXT, contains HTML source code. Here's the HTML code:
<FRAMESET rows="20%, 80%"><FRAME frameborder=1 noresize scrolling=no src="bannerPane.php"> and so on.

When I try to do something like:

$try = "<FRAMESET rows=\"20%, 80%\"><FRAME frameborder=1 noresize scrolling=no src=\"bannerPane.php\">"

echo $try;

Noting is displayed... I think the problem is the '<' and '>'.

So my first problem is to save this HTML code in a PHP variable. How can I do it? And secondly, once it's in a PHP variable, should I do something like addslashes($try) before executing the query?

THanks a lot for the help... I'm really about to die!
just adding '\' before the '"' is not sufficient

coopster

8:48 pm on May 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, implemens!

I think you are OK, except that you forgot to terminate your variable assignment with a semicolon. Put a semicolon (;) after the final quotation mark in the

$try
variable assignment operation.

And yes, addslashes to the variable prior to using it in an SQL statement.

implemens

8:37 am on May 7, 2004 (gmt 0)



Hi Coopster,

I'm sorry but it doesn't work either... code below:

<HTML>
<HEAD>
<TITLE>Let's see</TITLE>
</HEAD>
<BODY >

<H1 ALIGN="CENTER">Beginning...</H1>

<?
$try = "<FRAMESET rows=\"20%, 80%\"><FRAME frameborder=1 noresize scrolling=no src=\"bannerPane.php\">";
echo $try;
?>

<BR><b>End</b><BR>
</BODY>
</HTML>

brotherhood of LAN

8:42 am on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



implemens,

just to be on the safe side of escaping your strings for the DB, check out the mysql_escape_string() function, just to make sure its not another unescaped character preventing the insert.

Welcome to webmasterworld

implemens

10:40 am on May 7, 2004 (gmt 0)




I'm not yet with the MySQL problem... I'm just trying to store this string:
<FRAMESET rows=\"20%, 80%\"><FRAME frameborder=1 noresize scrolling=no src=\"bannerPane.php\">

into a variable (i.e, $try)

but this doesn't work:

<?
$try = "<FRAMESET rows=\"20%, 80%\"><FRAME frameborder=1 noresize scrolling=no src=\"bannerPane.php\">";
echo $try;
?>
nothing is displayed...

implemens

11:13 am on May 7, 2004 (gmt 0)




I GOT IT!

Ok, I'll tell what I found just in case someone wants to know what happened:

Let's take the following code:
<BODY>
Hola...
<?
$try = "<h1>hello</h1>";
echo $try;
?>
<BR>adios & Bye
</BODY>

The variable $try when echoes sends its content to the HTML browser and this one, "processes" the content. So when he finds a "<h1>hello</h1>", none of the <h1> and </h1> is displayed but interpreted as HTML tags and so Hello is displayed in the h1 format!

If we change this <h1>hello</h1> by the <FRAMSET... that I posted before, same happens but obviously this FRAMESET TAG was meaningless inside the BODY tag.

Thanks a lot ... it really helped me to tell my problem.

I wish y'all have a nice day!