INSERT times do not insert all data

Asked

Viewed 53 times

0

I have a little problem,

$alta = $_GET['alt-a'];
$altb = $_GET['alt-b'];
$altc = $_GET['alt-c'];
$altd = $_GET['alt-d'];

$correta = $_GET['correta'];
$img = $_SESSION['imagem'];
$questao = $_SESSION['questao'];


$inserta = mysqli_query($conn,"INSERT INTO alternativas VALUES ($codigo, '$alta', 'a'), ($codigo, '$altb', 'b'), ($codigo, '$altc', 'c'), ($codigo, '$altd', 'd') ");
$insert = mysqli_query($conn,"INSERT INTO questoes VALUES ($codigo, '$questao', '$img', '$correta')");
echo "Questão inserida com sucesso!";

When running this script, in most cases it works normal...but in some cases it does not enter all the information, in some cases it will insert $Insert completely, and $insert will be inserted 4 lines.. sometimes I only insert two, the problem is always in the $insert, sometimes I do not insert all.

  • How these parameters are sent?

  • Some by GET, others by SESSION, but I already put an echo to do the GET test and always receive all, but when recording in the bank sometimes not all.

  • By chance the code is your primary key?

  • This code is the last of the auto increment, an Insert inserts the question....

2 answers

1

I’m not sure what’s going wrong, but I can point to a possible solution. Try to place the fields of the table you are entering in the query.... type like this.

$insert = mysqli_query($conn,"INSERT INTO questoes(campo1,campo2,campo3,campo4) VALUES ($codigo, '$questao', '$img', '$correta')");
echo "Questão inserida com sucesso!";

I always put the names by default, and by organization in case someone catch your code later, but if Oce does not put can give some silly mistakes...try to put in both Sert, if not commented here. I hope I’ve cooperated!!!

  • I will try, before I had put each query of this separate, only that I was with the same problem, so I decided to unite all. only that did not solve, the funny thing is that the problem happens in a few moments...and stays for a while giving error...then disappears and works normal..

  • Strange, but you can leave in query together, but enter the fields of the table of the database as I did in the example ai...

  • I put the names, but it’s still the same.

0


Personal I got the Solution, the problem was that in the database the field of the table alternatives this with Primary Key, and when an alternative that already existed was inserted the INSERT.

  • Mark your answer as correct to close the question. Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.