I am new to php and stuff like that. But i decided to create my very simple insert page with PDO , so is PDO secure enough against SQL Injection attacks?
Here is my code:
<?php
//Database settings
$host = 'localhost';
$dbname= 'akar';
$user = 'akar';
$pass = 'raparen';
//Setting up the PDO
$dsn = "mysql:host=$host;dbname=$dbname";
$pdo = new PDO($dsn,$user,$pass);
//Check if user entered something, otherwise set the username variable string to nothing.
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
//Inserting the values to the database using named placeholders
$query = "INSERT INTO users (username,password) VALUES(:username,:password)";
$statement = $pdo->prepare($query);
$statement->execute(array(
':username'=> $username,
':password'=> $password
));
?>
My form:
<input type='text' placeholder='Enter Username here!' name='username' />
<input type='password' placeholder='Enter Password here!' name='password' />
<input type='submit' value='Submit' />
</form>