Jump to content

Syntax Error


supermoose37

Recommended Posts

So here's the deal. I've created a very basic web application in order to show the effects of SQL injections.

 

I plugged ' or 1=1-- into the username field, left the password blank and got the following

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1

in SELECT * FROM USERS WHERE Username='' or 1=1--'

 

<?php 
session_name("MyLogin");
session_start();

if($_GET['action'] == "login") {
$conn = mysql_connect("localhost", "root", "");
$db = mysql_select_db("test");
$name = $_POST['uname'];
$sql = "SELECT * FROM USERS WHERE Username='$name'";
$q_user = mysql_query($sql) or die(mysql_error() . ' <br /> in ' . $sql);

if(mysql_num_rows($q_user) == 1){

$data = mysql_fetch_array($q_user);
if($_POST['pword'] == $data['Password']){
header("Location: login_success.php");	
exit;
}else{
header("Location: login.php?login=failed&cause=".urlencode('Wrong Password'));
exit;
}
}else{
header("Location: login.php?login=failed&cause=".urlencode('Invalid User'));
exit;
}
}
if(session_is_registered("name") == false) {
header("Location: login.php");
}	
?>

Link to comment
https://forums.phpfreaks.com/topic/230943-syntax-error/
Share on other sites

I need to somehow get rid of that final '

 

I know that because when I put SELECT * FROM USERS WHERE Username='' or 1=1--' into phpMyAdmin, it returns the full user table.

 

Now, I was under the impression that putting -- allowed MySQL to ignore anything after it. (ie the final ')

 

Link to comment
https://forums.phpfreaks.com/topic/230943-syntax-error/#findComment-1188819
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.