When I post a variable to the database, of course, I use mysql_real_escape_string
. This way special characters go in the database as it should.
When I read this variable out of the database, I use mysql_real_escape_string again together with stripslashes
:
$var = stripslashes(mysql_real_escape_string($record['rowname']));
else it will give me slashes before quotes.
When I use this $var
I mentioned above and want to echo it, I simple can echo "$var"
because it has already been stripped and escaped, right?
And beside, if I use stripslashes
+ mysql_real_escape_string
on a variable, then POST this same variable again in the database, is mysql_real_escape_string
enough? Or do I need to stripslashes
this variable again?
Summarized:
As I know how this works:
- use
mysql_real_escape
EVERY time when using data with mysql: when reading query through variables just as posting variables to database. - Use
stripslashes
when echoing out escaped variables. - If you want to post
stripslashes
and escaped variables again to the database, you dont need to stripslash it again.
Do I miss htmlspecialchars
?
EDIT
So this is all wrong?
while( $record=mysql_fetch_array($result) )
{
$custid=mysql_real_escape_string($record['custid']);
$custsurname=mysql_real_escape_string($record['custsurname']);
$custmidname=mysql_real_escape_string($record['custmidname']);
$custforename=mysql_real_escape_string($record['custforename']);
$custcountry=stripslashes(mysql_real_escape_string($record['custcountry'])); }