Skip to main content
Go7hic13
Known Participant
June 19, 2012
Question

stripslashes function in PHP? Doesn't seem to work...

  • June 19, 2012
  • 1 reply
  • 9566 views

I've been trying to get the stripslashes() function in a PHP script to work but I'm not having any luck.  It seems like a very straightforward function but I'm still ending up with slashes in my comment/text area data.  Can anyone help?  I have some PHP books but they barely touch on the functionality.  (I'm new to PHP).  Thanks!  (BTW...  I removed the various attempts at calling the stripslashes() function).  The field I'm trying to remove the slashes from is the 'comment' variable.

Here is my short php script:

<?php // Script 1.0 - contactlist.php

if (isset($_POST['submit']) && !empty($_POST['submit'])) // Test if submit button named submit was clicked and not empty

{

          if (!empty($_POST['first']) && !empty($_POST['last'])  && !empty($_POST['email']) && !empty($_POST['phone']) && !empty($_POST['comment'])) {

                    $body = "First Name: {$_POST['first']}\nLast Name: {$_POST['last']}\nEmail Address: {$_POST['email']}\nContact Phone Number: {$_POST['phone']}\nContact Preference: {$_POST['contactvia']}\n\nBest Time To Contact: {$_POST['timepref']}\n\nComments:\n {$_POST['comment']}";

                    $body = wordwrap($body, 70);

                    mail('someone@somewhere.net', 'NEW Customer Inquiry Submission',$body, "From: {$_POST['email']}");

                    header('Location: index.html');  //Redirect to new url if form submitted

     }

}

?>

This topic has been closed for replies.

1 reply

Participating Frequently
June 19, 2012

Why are you needing to remove the slashes? Is magic quotes enabled? Are you using addslashes() somewhere?  What version of PHP are you running?

Go7hic13
Go7hic13Author
Known Participant
June 19, 2012

I'm assuming magic quotes is enabled.  I'm running sql/php v5.0 I believe.  I'm not adding any slashes either...  They are just there whenever I use a quote in the comment field.

Go7hic13
Go7hic13Author
Known Participant
June 21, 2012

With the first example I receive an error message...  Something referring to mysql.

The 2nd example didn't seem to help...  The script ran without a hitch but the slashes were still in the comment section of the generated email.  This is of course assumming I'm executing the script properly.  I'm not able to tell as I just started to us PHP.  I understand the code (I used to be a c coder) but as far as PHP script writing I have no idea of how to create it yet. 

Is this something I should ask the hosting company about?  I couldn't find any information on magic quotes in their FAQ or Help sections.  I am certain however I running PHP 5.3 though.

So lost...  at the moment.  


Can you tell me why my use of the stripslashes command below does not work?  I've tried multiple variations using stripslashes and each time I still see slashes in any comment which contains a quote.

<?php // Script 1.0 - contactlist.php

if (isset($_POST['submit']) && !empty($_POST['submit'])) // Test if submit button named submit was clicked and not empty

{

 

          if (!empty($_POST['first']) && !empty($_POST['last'])  && !empty($_POST['email']) && !empty($_POST['phone']) && !empty($_POST['comment'])) {

                    $body = "First Name: {$_POST['first']}\nLast Name: {$_POST['last']}\nEmail Address: {$_POST['email']}\nContact Phone Number: {$_POST['phone']}\nContact Preference: {$_POST['contactvia']}\n\nBest Time To Contact: {$_POST['timepref']}\n\nComments:\n {$_POST[stripslashes('comment')]}";

                    $body = wordwrap($body, 70);

                    mail('someone@somplace.net', 'NEW Customer Inquiry Submission',$body, "From: {$_POST['email']}");

                    header('Location: index.html');  //Redirect to new url if form submitted

     }

}

?>