1

Just a quick query really, In my PHP file, I have variables coming from my HTML form, like so:

$companyName = mysql_escape_string($_POST['compName']);
$AddLine1 = mysql_escape_string($_POST['add']);
$AddLine2 = mysql_escape_string($_POST['add1']);            
$AddLine3 = mysql_escape_string($_POST['add2']);

Throughout this script, I do a few select, insert statements with mysql. What I'm wondering is, is it okay to just use the mysql_escape_string once like above, or do I need to do it every time I use the variable?

Probably a really simple (or silly) question but I said I'd ask anyway.

1
  • 1
    You can reuse your $companyName, $AddLine1, $AddLine2 etc. variables again further down your script, as those hold the escape user input. is this what you meant? Commented Sep 15, 2010 at 13:24

4 Answers 4

2

Once is sufficient, $AddLine1-3 now holds "Safe" values

Sign up to request clarification or add additional context in comments.

1 Comment

That's great, thank you. I will accept this as the correct answer once I'm able to.
1

Yes, it is enough to do it once. Plus, if $_POST['val'] should be integer, you can do (int) $_POST['val'] and it will be totally safe too.

Comments

1

You might want to check out PHP.NET. They state that:

mysql_escape_string

has been deprecated and should be replaced with :

mysql_real_escape_string()

Reference:

http://php.net/manual/en/function.mysql-escape-string.php

1 Comment

@Maekins, thanks for that, I will check it out. Seems to be working fine so far anyway but good to know for the future!
0

You you working with standart php functions so you can use mysql_escape_string only then you need work with database queries.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.