svgmx5 Posted July 5, 2010 Share Posted July 5, 2010 So i've been getting this problem when using a contact form. For some reason i keep getting those n\r\ which i'm prety sure it stands for line breaks. I've tried using everything that i can think to get rid of them, but the only thing that seems to work is if i remove the stripslashes() from it, the issue with that is that if someone types 'i'm' it will display i\m. Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/ Share on other sites More sharing options...
phpSensei Posted July 5, 2010 Share Posted July 5, 2010 What do you mean contact form? You mean as in an email? Or do you store it in a database Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081614 Share on other sites More sharing options...
shortysbest Posted July 5, 2010 Share Posted July 5, 2010 Could you post your code? And for the problem with the I'm and that sort of thing with quotes inside of user submitted forms to fix it place your $_POST[''] and any other code around that inside of this mysql_real_escape_string() so for example it may look like this: mysql_real_escape_string(ucwords(strip_tags($_POST['name']))); Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081615 Share on other sites More sharing options...
svgmx5 Posted July 6, 2010 Author Share Posted July 6, 2010 Sorry, i should now by now that i need to place the code if(isset($_POST['send'])){ $name = mysql_real_escape_string(stripslashes($_POST['name'])); $message = mysql_real_escape_string(stripslashes($_POST['message'])); $insert_leads = "INSERT INTO leads (full_name, message) VALUES('$name', '$message')"; $run_insert = mysql_query($insert_leads) or die(mysql_error()); $to = ''.$admin_email.''; $subj = 'New contact submission'; $from = 'From:noreply@domain.com'; $body = ' The following lead was submited on '.$date_added.' from ip: '.$ip.': Name:'.$name.' Message: '.$message.' '; mail($to, $subj, $body, $from); $msg =' <h2>Your message has been sent</h2> '; } } I've also used nl2br so i can add line breaks where ever the user skips a line. The funny thing is that i've used this on same format on other forms and submitted them the same and never had that issue Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081671 Share on other sites More sharing options...
shortysbest Posted July 6, 2010 Share Posted July 6, 2010 Where are the n\r\ being added? could you maybe describe a little more of when it happens? Where? and is the problem with quotes fixed now? Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081673 Share on other sites More sharing options...
svgmx5 Posted July 6, 2010 Author Share Posted July 6, 2010 once again sorry, well say the user types in a message in the message textbox using a form, and adds a bunch of line breaks..(or just presses enter to many times) when it gets mailed to my email address each line break will be displayed as n\r\ and so on.. as far as the quotations, well keeping the mysql_real_escape_string(stripslashes()) fixes the that problem, but once i remove it it fixes the n\r\ problem but obviously the quotations don't show up do i make sense?? Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081674 Share on other sites More sharing options...
svgmx5 Posted July 6, 2010 Author Share Posted July 6, 2010 *the n\r show up on the message area* Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081675 Share on other sites More sharing options...
trq Posted July 6, 2010 Share Posted July 6, 2010 You need to track down where exactly they are coming from. The \n\r chars used for newlines are invisible and shouldn't be seen. The \n\r chars you are getting MUST be getting forced into your data somewhere along the line. Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081677 Share on other sites More sharing options...
shortysbest Posted July 6, 2010 Share Posted July 6, 2010 Yeah, Have you tried echoing out the $message into your webpage somewhere to see if they show up there? Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081678 Share on other sites More sharing options...
svgmx5 Posted July 6, 2010 Author Share Posted July 6, 2010 so even if i used nl2br($message) to add line breaks, those line breaks shouldn't show up on a email message Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081680 Share on other sites More sharing options...
svgmx5 Posted July 6, 2010 Author Share Posted July 6, 2010 @shortybest that's a good idea, i didn't even think about that Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081681 Share on other sites More sharing options...
trq Posted July 6, 2010 Share Posted July 6, 2010 Actually, looking at your code. You should only be using mysql_real_escape_string on the data being sent to the database, not the data being sent to the email. Re-arrange your code accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081682 Share on other sites More sharing options...
svgmx5 Posted July 6, 2010 Author Share Posted July 6, 2010 what if i used two variables to hold the message data..one that would go into the database and the other that will output the data? could that fix the problem Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081684 Share on other sites More sharing options...
shortysbest Posted July 6, 2010 Share Posted July 6, 2010 what if i used two variables to hold the message data..one that would go into the database and the other that will output the data? could that fix the problem try this <?php if(isset($_POST['send'])){ $dbname = mysql_real_escape_string(stripslashes($_POST['name'])); $dbmessage = mysql_real_escape_string(stripslashes($_POST['message'])); $name = stripslashes($_POST['name']); $message = stripslashes($_POST['message']); $insert_leads = "INSERT INTO leads (full_name, message) VALUES('$dbname','$dbmessage')"; $run_insert = mysql_query($insert_leads) or die(mysql_error()); $to = $admin_email; $subj = 'New contact submission'; $from = 'From:noreply@domain.com'; $body = 'The following lead was submited on '.$date_added.' from ip: '.$ip.': Name:'.$name.' Message:'.$message.''; mail($to, $subj, $body, $from); $msg ='<h2>Your message has been sent</h2>'; }} Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081685 Share on other sites More sharing options...
shortysbest Posted July 6, 2010 Share Posted July 6, 2010 what if i used two variables to hold the message data..one that would go into the database and the other that will output the data? could that fix the problem try this <?php if(isset($_POST['send'])){ $dbname = mysql_real_escape_string(stripslashes($_POST['name'])); $dbmessage = mysql_real_escape_string(stripslashes($_POST['message'])); $name = stripslashes($_POST['name']); $message = stripslashes($_POST['message']); $insert_leads = "INSERT INTO leads (full_name, message) VALUES('$dbname','$dbmessage')"; $run_insert = mysql_query($insert_leads) or die(mysql_error()); $to = $admin_email; $subj = 'New contact submission'; $from = 'From:noreply@domain.com'; $body = 'The following lead was submited on '.$date_added.' from ip: '.$ip.': Name:'.$name.' Message:'.$message.''; mail($to, $subj, $body, $from); $msg ='<h2>Your message has been sent</h2>'; }} I actually just noticed that this won't work at all how i initially thought, you would have to fetch the data from the database to send via email (I'm not the best at fixing code when i cannot view the results step by step myself, sorry about that) What i think may work is something like this: <?php if(isset($_POST['send'])){ $dbname = mysql_real_escape_string(stripslashes($_POST['name'])); $dbmessage = mysql_real_escape_string(stripslashes($_POST['message'])); $query = mysql_query("SELECT * FROM leads WHERE full_name='$dbname', message='$dbmessage'"); $sel = mysql_fetch_assoc($query); $name = $sel['full_name']; $message = $sel['message']; $run_insert = mysql_query("INSERT INTO leads (full_name, message) VALUES('$dbname','$dbmessage')") or die(mysql_error()); $to = $admin_email; $subj = 'New contact submission'; $from = 'From:noreply@domain.com'; $body = 'The following lead was submited on '.$date_added.' from ip: '.$ip.': Name:'.$name.' Message:'.$message.''; mail($to, $subj, $body, $from); $msg ='<h2>Your message has been sent</h2>'; }} Post the results once you've tried everything out. Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081688 Share on other sites More sharing options...
svgmx5 Posted July 6, 2010 Author Share Posted July 6, 2010 alright so i tried what @shortysbest said, and that seem to finally work. one last final thing..does any one know why this would only happen on certain server i guess..because I've used that method before, using one variable to both carry the db data and email data and i've never had any issues up until now. anyways thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081689 Share on other sites More sharing options...
svgmx5 Posted July 6, 2010 Author Share Posted July 6, 2010 hey @shorytbest well i didn't seem to any issues, i check the back end and its outputting the results properly with the code you sent me... Quote Link to comment https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/#findComment-1081690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.