I'm working on learning some basic security for a webserver.
I quickly noticed how the difference between storing the values in an array or not before executing them affected the security of the website.
Safe code:
$posts = $_POST['posts'];
$query = $pdo->prepare("insert INTO post (post) VALUES (:post)");
$data = array(
':post' => $posts);
$query->execute($data);
Not safe code:
$posts = $_POST['posts'];
$query = $pdo->prepare("insert INTO post (post) VALUES ('$posts')");
$query->execute($data);
- How would I be able to inject SQL code into the "Safe code"?
- Why is there a difference between the two?