Hi there,
I am trying to trim a textarea called comments in my enquiries form of character returns. I am told the trim function does this and have applied it to my php however it doesn't seem to be working.
<?php
$con = mysql_connect("*********","*********","*********");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("safe", $con);
$number = preg_replace('/[^0-9]/', '', $_POST['number']);
$realname = mysql_real_escape_string($_POST['realname']);
$email = mysql_real_escape_string($_POST['email']);
$comments = trim($_POST['comments']);
$comments = mysql_real_escape_string($_POST['comments']);
$sql="INSERT INTO Enquiries (Name, Number, Email, Comments, Date)
VALUES
('$realname','$number','$email','$comments', CURDATE())";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "";
mysql_close($con)
?>
Can anyone see why this might not be working?
Thanks in advance for any input. It is much appriciated.
Kind regards
Mike
Trim Text area (charcter return values)
Moderator: General Moderators
Re: Trim Text area (charcter return values)
Did you notice the button named "PHP Code" when you posted your question? Please use it.
What evidence tells you that trim() is not working?
Check your form for whitespace immediately after the opening <textarea> tag and immediately before the closing </textarea> tag.
What evidence tells you that trim() is not working?
Check your form for whitespace immediately after the opening <textarea> tag and immediately before the closing </textarea> tag.
Re: Trim Text area (charcter return values)
Hello,
Thank you for your reply. I know it isn't working because I uplaod the values to mysql database and the text is still sepparated by newlines.
As regards the whitespace, I'm not too sure. The code for the textarea is:
<TEXTAREA name=comments rows=10 cols=32></TEXTAREA><BR><BR><BR><INPUT type=submit value=Send name=send><BR><BR> </P></FORM>
Thanks again for your input. I really do appriciate it.
Kind regards
Mike
Thank you for your reply. I know it isn't working because I uplaod the values to mysql database and the text is still sepparated by newlines.
As regards the whitespace, I'm not too sure. The code for the textarea is:
<TEXTAREA name=comments rows=10 cols=32></TEXTAREA><BR><BR><BR><INPUT type=submit value=Send name=send><BR><BR> </P></FORM>
Thanks again for your input. I really do appriciate it.
Kind regards
Mike
Re: Trim Text area (charcter return values)
I wasn't kidding about the button named "PHP Code". It really does exist. You can even use it for HTML.
You might be misunderstanding what trim() does. It removes whitespace characters from only the beginning and end of a string.
If you want to remove certain characters from within a string, use str_replace().
If you don't want newlines in your submitted text, why are you using a textarea instead of a text input?
You might be misunderstanding what trim() does. It removes whitespace characters from only the beginning and end of a string.
If you want to remove certain characters from within a string, use str_replace().
If you don't want newlines in your submitted text, why are you using a textarea instead of a text input?
Re: Trim Text area (charcter return values)
Sorry about the PHP code button. I will use it from now on! : )
I had played with the str_replace() function however couldnt seem to get it to work either. Could you show me where it should be placed withing my original MySQL code?
I would like to keep the text area as it is for comments and questions. The text field is a bit small.
Thanks again for your time and assistance.
Kind regards
Mike
I had played with the str_replace() function however couldnt seem to get it to work either. Could you show me where it should be placed withing my original MySQL code?
I would like to keep the text area as it is for comments and questions. The text field is a bit small.
Thanks again for your time and assistance.
Kind regards
Mike