-2

I want security against hackers for my mysql connection in a php page.

I have database user's password different from the root password. And I've used this query:

function make_safe2($safe) 
{
$safe = strip_tags(mysqli_real_escape_string(trim($_POST['bname'] . $_POST['why'] . $_POST['email'] . $_POST['submit'])));
return $safe; 
}

Is there any more ways by which I can assure security against SQL injections and other hacking methods. I don't have any login page. I have a form with bname, why and email fields and a submit button. Does submit button needs escape string? :P Silly question I guess.

A complete syntax for other ways of preventions from SQL injections and other methods will be appreciated. :)

Mitesh Mynee
  • 757
  • 1
  • 6
  • 10

1 Answers1

2

You should use prepared statements with binded parameters.

$stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent);

$code = 'DEU';
$language = 'Bavarian';
$official = "F";
$percent = 11.2;

/* execute prepared statement */
mysqli_stmt_execute($stmt);

See the documentation

This answer is a complete guide to understanding how to prevent against SQL injection.

Community
  • 1
  • 1
Kermit
  • 33,827
  • 13
  • 85
  • 121