TO BE CLEAR I AM DELIBERATELY TRYING TO INJECT INTO MY OWN SITE.
I am trying to inject into one of my sites by using the order by statement to try and work out how many columns are in my table however I do not get any errors when I go greater than the number of columns I have.
My code is a very simple form, which calls a php file and then runs an SQL query.
Heres the php code:
 <?php
        $host="localhost"; // Host name 
        $username="root"; // Mysql username 
        $password="root"; // Mysql password 
        $db_name="Hack"; // Database name 
        mysql_connect("$host", "$username", "$password");//or die("cannot connect"); 
        mysql_select_db("$db_name");//or die("cannot select DB");
        $id = $_GET['id'];
        echo $id . "<br />";
        $qstr = "SELECT * from users WHERE username = '$id'";
        echo "<br />$qstr<br />";
        $query = mysql_query($qstr);
        $num = mysql_numrows($query);
        $count = 0;
        while ($count<$num){
            $id = mysql_result($query,$count,"id");
            $username = mysql_result($query,$count,"username");
            echo 'ID: ' . $id . '<br> Username: ' . $username . "<br/>";
            $count++;
        }
        if($num==0){
            echo "<br /><br /><br />";
            echo mysql_error();
        }
?>
Heres the form:
<html>
<h1>
    Search
</h1>
<form method="get" action="search.php">
    <input type="text" name="id">
    <input type="submit" value="Search user">
</form>
</html>
Lastly heres the "order by" statements I am trying in the url:
http://localhost:8888/search.php?id=admin%20order%20by%204
Please ignore the "%20" those are just spaces but chromes puts them in
So my question is why does by "order by" not work?
EDIT: Here is the SQL statement echoed out:
SELECT * from users WHERE username = 'admin order by 4'
 
     
     
     
     
    
$qstr
";` – user2157179 Dec 12 '13 at 19:23