In a local xampp server which I set up for development, I have a table like so:
CREATE TABLE `entries`
(
`id` int(10) UNSIGNED NOT NULL,
`title` varchar(100) NOT NULL,
`entry` text NOT NULL,
`date_entered` datetime NOT NULL
)
In order to learn how to secure my queries against SQL injections, I want to induce one (I am intentionally not using prepared statements). I have a query to insert an entry in this table like so:
$sql = 'insert into entries ( title , entry , date_entered ) '
. 'values("'
. $postTitle
. '","'
. $postEntry
. '","'
. $dateEntered
. '")';
It works (it does insert entries in the table), but I failed to induce SQL injection attack against it. Here is what I tried to insert in the $postEntry
field:
;drop table entries;
;drop table entries;'
';drop table entries;'
`;drop table entries;'
q';drop table entries;
q","e");drop table entries; --'
q","e");drop table entries;--
For the last value the SQL query became:
insert into entries ( title , entry , date_entered ) values("r","q","e");drop table entries;--","2016-08-18 10:35:36")
Still the entries table intact!
I modified the SQL string to use single quotes like so:
$sql = 'insert into entries ( title , entry , date_entered ) '
. ' values(\''
. $postTitle
. '\',\''
. $postEntry
. '\',\''
. $dateEntered
. '\')';
Then tried:
q','2016-5-5');drop table entries; --'
But still no luck! How should I produce SQL injection attack then? note : the proposed duplicate is not duplicate and not even an answer . the whole point of this question is to demo the expoite so that i make sure the security measures are working.