0
What is the correct way to use sprintf
in mysqli and make the return IF?
$rs = $mysqli->query(sprintf("INSERT INTO perguntas (chave, nome, email, idade, estado_civil, profissao, religiao, assunto, pergunta, `data`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
mysqli_real_escape_string($chave),
mysqli_real_escape_string($_POST['nome']),
mysqli_real_escape_string($_POST['email']),
mysqli_real_escape_string($_POST['idade']),
mysqli_real_escape_string($_POST['estado_civil']),
mysqli_real_escape_string($_POST['profissao']),
mysqli_real_escape_string($_POST['religiao']),
mysqli_real_escape_string($_POST['assunto']),
mysqli_real_escape_string($_POST['pergunta']),
mysqli_real_escape_string($data)));
if (mysqli_query($rs)) {
echo "<script>window.location = '".$baseURL."/enviar-aconselhamento&chave=$chave'</script>";
}else{
die('Error: ' . mysqli_error($mysqli));
}
That way I’m doing above is returning error:
Error: 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
You’re doing it wrong.
– Ivan Ferrer
That’s my question...rsrs, how to do it properly... can help?
– Tiago
@Ivanferrer Can help?
– Tiago
Have you consulted the manual of PHP.net?
– Ivan Ferrer
Why are you sprintf?
– Ivan Ferrer
How to prevent SQL code injection into my PHP code, the
sprintf()
is a great solution to generate the sql template and not to pass the values in legacy codes is still acceptable.– rray