Two small questions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joetheeskimo5
Forum Commoner
Posts: 43
Joined: Sun Dec 14, 2003 4:47 pm
Location: US
Contact:

Two small questions

Post by joetheeskimo5 »

1. How can I prvent PHP from automatically escaping text submitted through a form? Whenever PHP came to a ' symbol, it would automatically escape it. I don't want this because the text entered into the form is going to be displayed on the web page, and I don't want it do say "I''m" or "You''re".

2. How can I use the echo() function and then once it's displayed the text to save the file? To be more clear, I have a form. The user enters their username and comments. When they submit, they're brought to a page called comments.php, and they'll see their username and comments displayed on that page. I know how to do all that. What I'd like is for it to display their form info, and then save it to the file, so when someone else comes along, they'll see their info PLUS the first user's info.

I hope I was clear enough. :? Thanks in advance for your help.

Joe
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Use stripslashes(). I will remove all of the escaping.
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

Just put all info in to database and make user name primary key , so when user visit next time u can fetch all info from database thro username .
joetheeskimo5
Forum Commoner
Posts: 43
Joined: Sun Dec 14, 2003 4:47 pm
Location: US
Contact:

Post by joetheeskimo5 »

Staterra: Where should I put the stripslashes() function? before the echo() function?

phpcoder: Ehm....I didn't quoite understanmd that; could you explain how to do that?
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

stripslashes($_POST['blabla']);
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

Whenever you want to save any info for later use or for any other purpose there are two ways of doing one is by creating database and save all info in tables and other is creating files but later one is not recommanded, coz very difficult to search and update etc so best is to use database . As far as i understand ur que i think u wanna save user info .
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

first, when you submit the form, add slashes (with addslashes($string) ).
and then when you want to remove the slashes, just use stripslashes($string)...
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Why would you want to add the slashes when PHP automatically escapes the characters?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

If you do run addslashes on it, watch out:

From PHP.net
The PHP directive magic_quotes_gpc is on by default, and it essentially runs addslashes() on all GET, POST, and COOKIE data. Do not use addslashes() on strings that have already been escaped with magic_quotes_gpc as you'll then do double escaping. The function get_magic_quotes_gpc() may come in handy for checking this.
joetheeskimo5
Forum Commoner
Posts: 43
Joined: Sun Dec 14, 2003 4:47 pm
Location: US
Contact:

Post by joetheeskimo5 »

Alright, I understand now. Thanks everyone for your help.

btw, I'm using stripslashes not addslashes, so no need to worry...

Joe
Post Reply