5
I am learning php and would like to take a doubt if my code is vulnerable to sql Injection.
In case I’m putting together a form
<form method="POST" action="classes/cliente.class.php" enctype="multipart/form-data">
<input class="input" type="text" name="razaosocial" placeholder="Razão Social" onkeyup="maiuscula(this)">
<button class="button is-primary" type="submit" value="Cadastrar" name="novoCliente">CADASTRAR</button>
There in the other file I’m taking it this way
if (array_key_exists("novoCliente", $_POST)){
$razaosocial = $_POST["razaosocial"];
$sql = mysqli_query($conexao, "INSERT INTO cliente VALUES ('', '".$razaosocial."') ");
if ($sql){
echo "<script language='javascript' type='text/javascript'>window.location.href='../consultaCliente.php'</script>";
}
else{
echo "<script language='javascript' type='text/javascript'>alert('Erro no cadastro!');window.location.href='../cadastroCliente.php'</script>";
}
else
echo"<script language='javascript' type='text/javascript'>window.location.href='../cadastroUsuario.php'</script>";
Is that right? You’re vulnerable?
Always keep an eye out for user input. User inputs are dangerous as they are attack vectors. SQL is a powerful language (after all it controls your database) and you have entered user input in the middle of it without "sanitizing", is giving enough power to the user, who may be an invader. The golden rule is: "Select all user input" (Select all user input).
– rodorgas