943,960 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2263
  • PHP RSS
Jan 30th, 2009
0

stripslashes problem

Expand Post »
Hey All,

I've got a web page that displays multiple boxes of text using php. The text are coming from .txt files instead of using a database to store the data. I can update these text files when I want to change the information.

My problem is that I need stripslashes to be put in because I'm getting (don\'t) instead of (don't), and I can't figure out where to put the stripslashes function to make it work. This only happens when I use my update form. If I alter the .txt document manually, no problem, so my problem must lie in my update.php file.

Here is my Update.php file so you can see what I've done.
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. if($_POST['Submit']){
  3. $open = fopen("b12.txt","w+");
  4. $text = $_POST['update'];
  5. fwrite($open, $text);
  6. fclose($open);
  7. echo "File updated.<br />";
  8. echo "File:<br />";
  9. $file = file("b12.txt");
  10. foreach($file as $text) {
  11. echo $text."<br />";
  12. }
  13. echo "<p><a href=\"./index_update.php\">click here to return to main page</a></p>";
  14. }else{
  15. $file = file("b12.txt");
  16. echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
  17. echo "<textarea Name=\"update\" cols=\"50\" rows=\"20\">";
  18. foreach($file as $text) {
  19. echo $text;
  20. }
  21. echo "</textarea>";
  22. echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
  23. </form>";
  24. }
  25. ?>

if anyone can point me in the right direction it would be great. I'm still new to this but learning all the time.

Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster
rickarro is offline Offline
107 posts
since Jan 2008
Jan 30th, 2009
0

Re: stripslashes problem

The $_POST array variable may be slashed. To get rid of the slashes, just do this:

PHP Syntax (Toggle Plain Text)
  1. $text = stripslashes($_POST['update']);
Last edited by ardav; Jan 30th, 2009 at 11:36 am.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 949
Sarcastic Poster
ardav is offline Offline
6,698 posts
since Oct 2006
Jan 30th, 2009
0

Re: stripslashes problem

PHP Syntax (Toggle Plain Text)
  1. $text = stripslashes($_POST['update']);

Sorry Ardav, in between reading the post and answering
Last edited by almostbob; Jan 30th, 2009 at 11:53 am.
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Jan 30th, 2009
0

Re: stripslashes problem

Thank you for the reply, but it didn't work, i'm still getting the \ before the apostrophy. I'll explain a little more. My main page (index.php) uses include statements within html:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. include('b12.txt');
  3. ?>
I then have an update button that I click which takes me through a login page to an "update_index.php" page. This page has edit links for each of the 12 header and body .txt files. When I click the edit link, it opens the .txt file in a file called update.php (displayed above) where the text is changed. I think this is where my problem is but i'm not sure now that your instruction didn't work.

I didn't have this problem until I had to uncomment the magic_quotes_gpc = on in my php.ini file for another program.
Do you think my problem lies elsewhere or is the file above my problem? Ideas?
Reputation Points: 10
Solved Threads: 1
Junior Poster
rickarro is offline Offline
107 posts
since Jan 2008
Jan 30th, 2009
0

Re: stripslashes problem

test Just the update file
on your local server run the update.php against a blank(empty) b12.txt and examine the stored data,
then against an edit of the edited file
using the modified $text = stripslashes($_POST['update']);$text = stripslashes($_POST['update']); if that works the bug is elsewhere,

it should work
and the bug should be elsewhere
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Jan 30th, 2009
0

Re: stripslashes problem

magic_quotes_gpc should be off. Ych-a-fi mochandra diawl!!! Removed in pHp 6.0 anyway. All your text should be escaped and slashed properly. Addslashing and Stripslashing should be under your control, not left to some hocus pocus invisible function!

What'll happen when our hosts upgrade to php6? Will the magic go 'poof'?

Even pHp's online manual says not to rely on it.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 949
Sarcastic Poster
ardav is offline Offline
6,698 posts
since Oct 2006
Jan 30th, 2009
0

Re: stripslashes problem

Click to Expand / Collapse  Quote originally posted by almostbob ...
test Just the update file
on your local server run the update.php against a blank(empty) b12.txt and examine the stored data,
then against an edit of the edited file
using the modified $text = stripslashes($_POST['update']);$text = stripslashes($_POST['update']); if that works the bug is elsewhere,

it should work
and the bug should be elsewhere

If I understand you correctly, i'm to empty the b12.txt file, then add data and see what happens? When I empty the file, it displays nothing as it should. When I add data, I use simply the word "don't", and it comes out don\'t.

I'm not sure where else the problem could be, the page that displays it is a simple include statement (in this case
PHP Syntax (Toggle Plain Text)
  1. include('b12.txt');
. The update.php file is writing the \ to the txt file. I can edit the b12.txt file directly, remove the \ and save it, and it displays like it should. I must be doing something wrong, I just can't figure out what.
Last edited by rickarro; Jan 30th, 2009 at 1:38 pm. Reason: fix code markings
Reputation Points: 10
Solved Threads: 1
Junior Poster
rickarro is offline Offline
107 posts
since Jan 2008
Jan 30th, 2009
0

Re: stripslashes problem

Click to Expand / Collapse  Quote originally posted by ardav ...
magic_quotes_gpc should be off. Ych-a-fi mochandra diawl!!! Removed in pHp 6.0 anyway. All your text should be escaped and slashed properly. Addslashing and Stripslashing should be under your control, not left to some hocus pocus invisible function!

What'll happen when our hosts upgrade to php6? Will the magic go 'poof'?

Even pHp's online manual says not to rely on it.

I agree, but I've got to go through the other program i'm running and get that fixed because it was not slashed properly from the beginning. But in the mean time I just want to get this other portion right until I can take the time to fix the other one. Fortunately I'm doing my own hosting so a php upgrade will not be coming anytime soon. So much for small blessings
Reputation Points: 10
Solved Threads: 1
Junior Poster
rickarro is offline Offline
107 posts
since Jan 2008
Jan 30th, 2009
0

Re: stripslashes problem

Thank you almostbob and ardav for your help. It appears that your fix did work, but required a reboot on my part. Go figure. But the problem is fixed. I can now work on getting the slashes corrected in the other program, time willing.

Much appreciated guys!!!!!
Reputation Points: 10
Solved Threads: 1
Junior Poster
rickarro is offline Offline
107 posts
since Jan 2008
Jan 30th, 2009
0

Re: stripslashes problem

It were Gremlins
Gremlins wot dunnit
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Problem retaining data in a drop down box
Next Thread in PHP Forum Timeline: help with my scripot PLEASE!!! anyone?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC