Welcome to WebmasterWorld Guest from 54.145.13.215

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Inserting special characters in MySql with PHP

Inserting special characters in MySql with PHP

     
4:27 pm on Mar 13, 2006 (gmt 0)

New User

5+ Year Member

joined:Mar 13, 2006
posts:16
votes: 0


I got problem with inserting following code in mysql:

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: [new-url.com"...] );
?>

or

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently" Response.AddHeader "Location", " [new-url.com"...]
>

i want that this code is shown like this on page, any suggestion?

10:14 pm on Mar 13, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
posts:3416
votes: 0


Welcome to WebmasterWorld [webmasterworld.com], bsaric!

What problem are you experiencing?

Don't forget that you can't send a header [php.net] if you've already sent any output. In other words, header() must come BEFORE any echo or print statements.

12:54 am on Mar 14, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 30, 2005
posts:515
votes: 0


I think they are referring to storing special characters in mysql - look up the "mysql_real_escape_string" function
1:21 pm on Mar 14, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 8, 2004
posts:500
votes: 0


html_entities(mysql_real_escape_string($variable));

for echoing:

html_entity_decode(stripslashes($variable));

3:12 pm on Mar 14, 2006 (gmt 0)

New User

5+ Year Member

joined:Mar 13, 2006
posts:16
votes: 0


yes, im talking about inserting special characters in mysql, and im trying to pull it out in my tutorials as example code, without code execution
7:03 pm on Mar 14, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
posts:3416
votes: 0


Ahhh, now I understand. The different header code confused me into thinking it was a header problem. dmmh has the answer then, html_entities(). (Although I think that bsaric plans on displaying the actual code on the page, like in a PHP tutorial, in which case he will not need html_entity_decode().)
7:09 pm on Mar 14, 2006 (gmt 0)

New User

5+ Year Member

joined:Mar 13, 2006
posts:16
votes: 0


yes, im trying to do that, and i just can't find solution for this code above
9:44 pm on Mar 14, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
posts:3416
votes: 0


html_entities() [php.net] will turn all the <,>,and every other bit of special code into it's respective html entities: &lt;, &gt;, etc.

Then you just echo the actual data you inserted into the database.

8:22 am on Mar 15, 2006 (gmt 0)

New User

5+ Year Member

joined:Mar 13, 2006
posts:16
votes: 0


thanks i will try :)