Previously I used general mysqli
queries to insert values in database with real_escape_string
for security but everyone seems to use prepared statements for better security. To increase security and prevent sql injection I am going to replace my code with prepared statements but I wanted to know that how much secure is prepared statement given below. Can you suggest any more improvement for better security?
$stmt = mysqli_prepare($DB_connection,"INSERT INTO `posts`(`example`, `example2`) VALUES ('$for_example',?)");
mysqli_stmt_bind_param($stmt, 's', $_POST['username']);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
I get values from a form using POST method and add them to database. Can users replace values in database by sql injection?
Thanks for any help in advance.