| | |
stripslashes problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 100
Reputation:
Solved Threads: 1
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.
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.
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)
<?php if($_POST['Submit']){ $open = fopen("b12.txt","w+"); $text = $_POST['update']; fwrite($open, $text); fclose($open); echo "File updated.<br />"; echo "File:<br />"; $file = file("b12.txt"); foreach($file as $text) { echo $text."<br />"; } echo "<p><a href=\"./index_update.php\">click here to return to main page</a></p>"; }else{ $file = file("b12.txt"); echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" cols=\"50\" rows=\"20\">"; foreach($file as $text) { echo $text; } echo "</textarea>"; echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n </form>"; } ?>
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.
The $_POST array variable may be slashed. To get rid of the slashes, just do this:
PHP Syntax (Toggle Plain Text)
$text = stripslashes($_POST['update']);
Last edited by ardav; Jan 30th, 2009 at 11:36 am.
PHP Syntax (Toggle Plain Text)
$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
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
•
•
Join Date: Jan 2008
Posts: 100
Reputation:
Solved Threads: 1
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:
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?
PHP Syntax (Toggle Plain Text)
<?php include('b12.txt'); ?>
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?
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
it should work
and the bug should be elsewhere
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
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
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.
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.
•
•
Join Date: Jan 2008
Posts: 100
Reputation:
Solved Threads: 1
•
•
•
•
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)
include('b12.txt');
Last edited by rickarro; Jan 30th, 2009 at 1:38 pm. Reason: fix code markings
•
•
Join Date: Jan 2008
Posts: 100
Reputation:
Solved Threads: 1
•
•
•
•
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
![]() |
Similar Threads
- Upload images to a folder script problem (PHP)
- problem in setting session (PHP)
- page loading problem (PHP)
- Login Problem. Please Help. (PHP)
- File Attachment Small Problem (PHP)
- PHP MySQL problem (PHP)
- Problem with $_POST (PHP)
- PHP sessions/$_POST problem. Too Stressed today! (PHP)
- Error message: can I fix the problem? (Existing Scripts)
- search and results problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: display image from mysql db in php page
- Next Thread: help with my scripot PLEASE!!! anyone?
| Thread Tools | Search this Thread |
ajax apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error errors execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google href htaccess html image include insert integration ip java javasciptvalidation javascript joomla keywords limit link login loop mail matching menu mlm multiple mysql number oop paypal pdf php problem query radio random recursion recursive regex remote script search server sessions shot sms soap source space sql subscription syntax system table tag tutorial tutorials update upload url validator variable video web xml youtube






