I want to do sql injection testing. For this, I created a db called person and a table called users. I am passing some sql statements to test the sql ingest. It gives error, but does not execute the query:
database connection file:
connection.php
$server="localhost";
$user="root";
$password="";
$database="pessoa";
//conexao com servidor de banco
$connect = mysql_connect($server, $user, $password) or print(mysql_error());
//se a conexao falhar
if (!$connect) {
echo "Conexão com servidor errou";
}
else {
//usar database
$selectDB = mysql_select_db($database, $connect);
//se database falhar
if (!$selectDB) {
echo "Conexão com o banco errou";
}
}
index.html file
<html>
<body>
<form name="buscar" id="buscarId" action="server.php" method="post">
<label for="Nome">Nome</label>
<input type="text" name="nome" id="nomeId">
<input type="submit" value="Buscar">
</form> >
</body>
</html>
server.php file
<?php
include('connect.php');
buscar();
function buscar() {
echo "<p>";
$select = "select * from usuarios where nome='$_POST[nome]'";
$query = mysql_query($select);
$rows=mysql_num_rows($query);
if ($rows==0) {
echo "Nome não encontrado";
} else {
while ($dados=mysql_fetch_array($query)) {
print_r($dados);
}
}
}
?>
In the form that looks for the name, instead of entering the name, I put a query:
select * from users
Of course this is not a command for the bank, it is a search because it is in single or double quotation marks:
select * from usuarios
gives the error:
(!) Warning: mysql_num_rows () expects parameter 1 to be resource, boolean given in \ path \ folder.
I already did:
$select = "select * from usuarios where nome='.$_POST[nome].'";
debugging gets:
select * from usuarios where nome='.select * from usuarios.', ou seja, não executa o que está em $_POST;
And I also did:
$select = 'select * from usuarios where nome=$_POST[nome]';
Também não funciona. Só não entendi porque tem que concatenar.