Jump to content

Recommended Posts

Which way round should these functions be :

 

<?php
$Message = mysql_real_escape_string(stripslashes($row['Message']));
?>

 

Or

<?php
$Message = stripslashes(mysql_real_escape_string($row['Message']));
?>

 

Because it keeps putting this into my paragraphs:

 

Good for you\r\n\r\nExpect lot\'s more

 

Very annoying having the \r\n\r\n, i don't know how to get rid of it =/

Link to comment
https://forums.phpfreaks.com/topic/134680-what-way-round/
Share on other sites

Is this being used when you're getting data out of the database? If so you don't need even need to run mysql_real_escape_string in this case. mysql_real_escape_string should on be used on variables (which contain strings) that are going to be used within an SQL query.

Link to comment
https://forums.phpfreaks.com/topic/134680-what-way-round/#findComment-701332
Share on other sites

You should only be using stripslashes if magic quotes are ON, and it should be done before mysql_real_escape_string, and as wildteen said, all that is only done on data going into the database, not out ($row['var'] is a common array used when retrieving data, that's why wildteen asked).  If you read the mysql_real_escape_string manual entry, it explains how to use it.

Link to comment
https://forums.phpfreaks.com/topic/134680-what-way-round/#findComment-701338
Share on other sites

Well it gets it from a database table, but then its also going to go back into a database table...

 

So it goes like this:

 

Retrieve data from field from table1

assign to $Message

Input $Message into table2

Echo $Message from table2

 

which is when the /r/n/r/n etc turns up.. and i do have the strip slashes done first... i was told that even if magic quotes are on or off theres no harm in having the strip slashes function in there?

Link to comment
https://forums.phpfreaks.com/topic/134680-what-way-round/#findComment-702637
Share on other sites

Maybe I'm misunderstanding you, but if you're just pulling data out of one table and putting it into another, there's no reason for you to be using striplashes or mysql_real_escape_string at all.  The only time you need to do any of that sort of thing is when the data is coming from the user. 

Link to comment
https://forums.phpfreaks.com/topic/134680-what-way-round/#findComment-702646
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.