Forum Moderators: coopster

Message Too Old, No Replies

Help, please...stripslashes problem.

Why doesn't this work?

         

ksponline

12:05 am on Jan 19, 2004 (gmt 0)

10+ Year Member



Hi,

I don't understand why form results still have slashes in them after using stripslashes (comments: This is and isn\'t a test of a form. \"What do you think or don\'t think?\"
)

What's wrong with the code? I've tried various things and searched forums and google, but I can't determine what I need to do.


<?php
$PageTitle = "Comments";
$name = stripslashes(trim($name));
$email = stripslashes(trim($email));
$comments = stripslashes(trim($comments)); // Tried with and without this line

foreach($HTTP_POST_VARS as $key => $value)
{
if ($value!="") {
$message .= $key . ": " . $value;
$message = stripslashes(trim($message));
$message .= "\n";
}
}
mail("me@domain.com","Comment Submission","$message","From: $name <$email>");
header ("Location: /fileupload/confirm_2.php");

?>

This has plagued me for a long time...I'm hoping some php guru will share some insight and wisdom.

Thanks,
ksp

coopster

1:29 am on Jan 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm not quite sure I fully understand your issue but one problem I notice is that you are overwriting your $message variable during each iteration of your loop:

foreach($HTTP_POST_VARS as $key => $value)
{
if ($value!="") {
$message .= $key . ": " . $value;
$message = stripslashes(trim($message));
$message .= "\n";
}
}

Try this:

$message = '';
foreach($HTTP_POST_VARS as $key => $value) {
if ($value!="") $message .= $key . ": " . stripslashes(trim($value)) . "\n";
}

ksponline

2:25 am on Jan 19, 2004 (gmt 0)

10+ Year Member



Many, many thanks. That worked! I appreciate your taking time to show me the correct code.

Kind regards,
ksp