First of all, let’s get down to the basics.
You are leaving the procedural mode of mysqli_query
for object-oriented. I commented this case a short time ago in this question.
The problem is that you are still messing up the procedural way with the object-oriented one when working with mysqli_query
.
How would it be right to work with the object-oriented `mysqli_query:
Connection (Not that yours is wrong)
// Conecta ao banco de dados
$mysqli = new mysqli('127.0.0.1', 'usuario', 'senha', 'banco');
Validating the connection
// Verifica se ocorreu algum erro
if (mysqli_connect_errno()) {
die('Não foi possível conectar-se ao banco de dados: ' .
mysqli_connect_error());
exit();
}
Try to use the Prepared Statements. Make your life easier
/* Prepared statement, Primeiro parte prepare o sql.
Verifique se não ocorreu erro */
if (!($stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (?)"))) {
echo "Falha no Prepare: (" . $mysqli->errno . ") " . $mysqli->error;
}
// Segunda parte passe os parâmetros e execute a query
$id = 1;
if (!$stmt->bind_param("i", $id)) {
echo "Falha no bind_param: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
echo "Falha ao executar a query: (" . $stmt->errno . ") " . $stmt->error;
}
One more example. Another thing, avoid using the @
at the bank or anywhere in your code. Omitting errors and warnings only harms you to produce a good code.
I hope it helps you.
See if this looks like a mistake like this:
mysqli_query($con,$sql) or die(mysqli_error($con));
. Do not use@
because it hides the error so you do not see the error message.– rray
I am using easyui datagrid, so even if you have error does not appear....
– Andre Maia
Access this php file directly, you can put the fixed values to
$sigla
and$nome
test-only.– rray
{"idsector":48,"acronym":null,"name":null} returned that.... saved direct.
– Andre Maia
you didn’t forget to put the
$_POST['nome']
something like that? at least you don’t have that code in the question.– rray
not.... it works perfectly with mysql_ but has some problem in mysqli
– Andre Maia
edited there... had forgotten to show this part.....
– Andre Maia
worked was something with the mysqli_set_charset($con,"utf8");
– Andre Maia