2. When i echo the text, to format it like it was typed into the text box?
[man]nl2br/man
... as mentioned in very good advice above, will convert any \n to <br>
You should avoid using addslashes and stripslashes in your scripts.
why?
Because doing stripslashes only indicates,
that you have too many added slashes before storing data.
If you avoid add slashes, if not needed, than there is no need to strip them extra slashes later.
It is actually a fact, regarding MySQL (i know from own experience and from expert articles)
that we should never need to do any stripslashes when pulling data from db.
Study the good advices at PHP Manual:
http://docs.php.net/get_magic_quotes_gpc
http://docs.php.net/manual/en/security.magicquotes.php
http://docs.php.net/manual/en/security.magicquotes.whynot.php
Why not to use Magic Quotes
* Performance Because not every piece of escaped data is inserted into a database, there is a performance loss for escaping all this data. Simply calling on the escaping functions (like addslashes()) at runtime is more efficient. Although php.ini-dist enables these directives by default, php.ini-recommended disables it. This recommendation is mainly due to performance reasons.
* Inconvenience Because not all data needs escaping, it's often annoying to see escaped data where it shouldn't be. For example, emailing from a form, and seeing a bunch of \' within the email. To fix, this may require excessive use of stripslashes().
x
Go for Real Escape of Strings, instead of some kinda magic escaping of database entries:
http://docs.php.net/mysql_real_escape_string
// Reverse magic_quotes_gpc/magic_quotes_sybase effects on those vars if ON.
if(get_magic_quotes_gpc()) {
$product_name = stripslashes($_POST['product_name']);
$product_description = stripslashes($_POST['product_description']);
} else {
$product_name = $_POST['product_name'];
$product_description = $_POST['product_description'];
}
// Make a safe query
$query = sprintf("INSERT INTO products (`name`, `description`, `user_id`) VALUES ('%s', '%s', %d)",
mysql_real_escape_string($product_name, $link),
mysql_real_escape_string($product_description, $link),
$_POST['user_id']);
mysql_query($query, $link);