I have this comment form where the only inputs are a name and a textarea for a comment.
My question is: how can I be sure that there is no way to use SQL injection in my code? I found a couple of guides for this, but I am not sure how to make them work with my code.
<?php
if(isset($_POST['submit'])){
$pvm = date("F j, Y");
$postId = $_GET["post"];
$lahettaja = $_POST['name'];
$kommentti = $_POST['comment'];
$sql = "INSERT INTO kommentti (post_id,kommentti_pvm,kommentti,lahettaja) VALUES (:post,:kommentti_pvm,:kommentti,:lahettaja)";
$kysely = $yhteys->prepare($sql);
$kysely->bindParam("post", $postId);
$kysely->bindParam("kommentti_pvm", $pvm);
$kysely->bindParam("kommentti", $kommentti);
$kysely->bindParam("lahettaja", $lahettaja);
$kysely->execute();
}
?>