I get the errors:
Notice: Undefined variable: db in C:\xampp\htdocs\sqltest.php on line 18
Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\sqltest.php on line 18
I used the code from this How can I prevent SQL injection in PHP?
I'm entirely new to PDO and that sort of thing, and on my apache server it's using php 5.3.
I'm just testing this out, I know I didn't use good coding practice.
my code:
$con = mysql_connect("localhost","root","") or die('error');
mysql_select_db("safe",$con);
if(isset($_POST['lastinput'])){
$prepared = $db->prepare('SELECT * FROM data WHERE last = :last');
$prepared->execute(array(':last' => $_POST['lastinput']));
$rows = $prepared->fetchAll();
echo $rows['first'];
}
mysql_close($con);