I know about the "little bobby tables" scenario and was just wondering if this code is vulnerable to such SQL injections.
I am fairly new to PHP and am curious about this.
My code for a login script:
<?php
# session
session_start();
# get the variables from login.php
$userid = $_POST["userid"];
$pword = $_POST["pword"];
mysql_real_escape_string($userid);
mysql_real_escape_string($pword);
# query the DB
$query = mysql_query ("
SELECT username
FROM login
WHERE username = '$userid'
AND pword = '$pword';
");
if ($query === FALSE) {
die('There has been an error.<br><br> Please re-enter your Login Details on the <b><a href="login.php">Login</a></b> Page.<br><br>');
}
$result = mysql_fetch_assoc($query);
$record = $result['username'] ;
# valid login
# check if session is operational, if so redirect the user
# to the correct page
if ($record != null) {
$_SESSION['login'] = true;
header( 'Location: index.php' ) ;
}
# invalid login
else if ($record == null) {
echo "
We cant find you on the system.
<br/>
Please return to the <b><a href='login.php'>Login</a></b> page and ensure that
<br/>
you have entered your details correctly.
<br><br>
<b>Warning</b>: You willl be redirected back to the Login Page
<br> in <b> <span id='counter'>10</span> Second(s)</b>";
}
?>
The main reason for asking this is that when I login inputting:
'user'); DROP TABLE Login;--'
it doesn’t drop the table.
My question is: Am I typing in the right SQL injection?