Problem
I have the below snippet in a website that I'm building at the moment. I know it is not secure due to SQL injection etc. but what is the correct way to solve that? I see related questions asking the same thing but with MySQL, and for that there is PDO, but PDO_OCI is experimental so I don't want to use it.
What other options do I have? Do I just create a function to strip certain characters and wrap that around the $_POST
, something like str_replace(';', '', $_POST['username']);
?
The below snippet is the only part of the website that actually takes user input, $_POST
, in a query so I just need to make sure that I get the below correct.
Code
<?php
if (!empty($_POST)) {
$stid = oci_parse($conn, "SELECT CustomerNo FROM Customers WHERE Username = '" . $_POST['username'] . "' AND Password = '" . $_POST['password'] . "'");
oci_execute($stid);
$row = oci_fetch_array($stid, OCI_NUM);
if (!empty($row['0'])) {
session_start();
$_SESSION['customer'] = $row['0'];
$_SESSION['username'] = $_POST['username'];
}
oci_free_statement($stid);
oci_close($conn);
}
?>