stripslashes problem

Thread Solved

Join Date: Jan 2008
Posts: 100
Reputation: rickarro is an unknown quantity at this point 
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster

stripslashes problem

 
0
  #1
Jan 30th, 2009
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.
  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,002
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 129
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: stripslashes problem

 
0
  #2
Jan 30th, 2009
The $_POST array variable may be slashed. To get rid of the slashes, just do this:

  1. $text = stripslashes($_POST['update']);
Last edited by ardav; Jan 30th, 2009 at 11:36 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,349
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 163
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: stripslashes problem

 
0
  #3
Jan 30th, 2009
  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.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 100
Reputation: rickarro is an unknown quantity at this point 
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster

Re: stripslashes problem

 
0
  #4
Jan 30th, 2009
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:
  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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,349
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 163
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: stripslashes problem

 
0
  #5
Jan 30th, 2009
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
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,002
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 129
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: stripslashes problem

 
0
  #6
Jan 30th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 100
Reputation: rickarro is an unknown quantity at this point 
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster

Re: stripslashes problem

 
0
  #7
Jan 30th, 2009
Originally Posted by almostbob View Post
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
  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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 100
Reputation: rickarro is an unknown quantity at this point 
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster

Re: stripslashes problem

 
0
  #8
Jan 30th, 2009
Originally Posted by ardav View Post
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 100
Reputation: rickarro is an unknown quantity at this point 
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster

Re: stripslashes problem

 
0
  #9
Jan 30th, 2009
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!!!!!
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,349
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 163
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: stripslashes problem

 
0
  #10
Jan 30th, 2009
It were Gremlins
Gremlins wot dunnit
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC