array conversion error for string

0

I need to insert into the database variables that are in a php array, I typed the catch:

    for ($i=1; $i <= 20 ; $i++) { 
    $sqlp= "INSERT INTO pergunta$i (pergunta, opcao1, valor1, opcao2, valor2, opcao3, valor3, opcao4, valor4, opcao5, valor5, opcao6, valor6, opcao7, valor8, opcao2, valor8) VALUES ('$tabela[$i][1]','$tabela[$i][2]','$tabela[$i][3]','$tabela[$i][4]','$tabela[$i][5]','$tabela[$i][6]','$tabela[$i][7]','$tabela[$i][8]','$tabela[$i][9]','$tabela[$i][10]','$tabela[$i][11]','$tabela[$i][12]','$tabela[$i][13]','$tabela[$i][14]','$tabela[$i][15]','$tabela[$i][16]','$tabela[$i][17]',)";
        $salvar= mysqli_query($conexao, $sqlp);
}

When executed, the browser returns conversion error from array to string, how can I solve it?

    
asked by anonymous 20.06.2017 / 00:41

2 answers

1

As the use of the comma is a recurring problem for the user of the written language, the same thing happens in programming.

There's a comma left over in , $tabela[$i][17] ,)

remove the comma before the closing of the parenthesis $tabela[$i][17] )

THE FATAL VEHICLE

Russian Tsarina Maria Fyodorovna once saved the life of a man, only changing the comma of his sentence of place. Very intelligent, she who did not agree with the decision of her husband, Alexander II, used the artifice to follow.

The Tsar sent the prisoner to prison and death in the Siberia dungeon.

At the end of the arrest warrant, it was written: "Excuse me, send it to Siberia"

Mary ordered that they draft a new order, and pretending to read the original document, changed a comma, turning the order into: "Forgiveness, impossible to send to Siberia" and the prisoner was released. >

  

That's it. Beware of her. Or the lack of it.

    
20.06.2017 / 02:47
0

Normally this error occurs when you try to directly insert an array type into the query. This is because the database does not accept this type of data. To write an array to a record you first need to convert it to a string by putting a separator that can be any character:

$ arrayasigned = implode ('separator', $ array);

So your array will be written to the database. In your case it is difficult to state the problem of the error because you must know how you built this array that you are trying to record. it is two-dimensional.

    
21.06.2017 / 17:58