0
I have a form of questions with multiple questions, after the person answer has a save button that sends the answers and questions to the salva.php
Follow the get (url):
salva.php?
data_cadastro=2017-07-08
& cli_id = 1
& cli_nome=OTACIO+BARBOSA
& cli_end=RUA+A
& cli_tel=3333333333
& cli_data_nasc=1900-01-01
& cli_cidade=TESTE
& cli_estado=MG
& usu_id = 1
& 1=3
& 2=0
& 3=1
& 4=5
& 5=3
& 6=1
& 7=0
& 8=3
& 9=0
& 10=1
& 11=5
& 12=5
& 13=5
& 14=3
& 15=3
& 16=0
& 17=0
& 18=1
& 19=1
& 20=0
& 21=0
& 22=1
& 23=3
& 24=5
I need to save this data in table responses:
resp_fixa_id
resp_fixa_id_perg
resp_fixa_id_cliente
resp_fixa_id_resp
resp_fixa_data_cad
As follows::
resp_fixa_id = data_cadastro
resp_fixa_id_perg = ( é o sequencial mmostrado de 1 a 24 )
resp_fixa_id_cliente = cli_id
resp_fixa_id_resp = é o que vem na frente do sequencial (1 = 3 (no caso seria o 3))
resp_fixa_data_cad = data_cadastro
In other words, you need to leave it as follows to insert it in the bank:
INSERT INTO resposta (resp_fixa_id,resp_fixa_id_perg,resp_fixa_id_cliente,resp_fixa_id_resp,resp_fixa_data_cad)
VALUES('NULL','1','1','3','2017-07-08');
INSERT INTO resposta (resp_fixa_id,resp_fixa_id_perg,resp_fixa_id_cliente,resp_fixa_id_resp,resp_fixa_data_cad)
VALUES('NULL','2','1','0','2017-07-08');
INSERT INTO resposta (resp_fixa_id,resp_fixa_id_perg,resp_fixa_id_cliente,resp_fixa_id_resp,resp_fixa_data_cad)
VALUES('NULL','2','1','1','2017-07-08');
How could I make this conversion ?
Note: This sequence is the number of questions on the screen that the person answered, more is not stay, can be more or even this amount.
Complement:
$total_de_perguntas = count($_POST)-9;
$VarLoja = $_POST['loja'];
$VarDataCadastro = $_POST['data_cadastro'];
$VarUsuario = $_POST['usuario'];
$VarNome = $_POST['cli_nome'];
$VarEndereco = $_POST['cli_end'];
$VarTelefone = $_POST['cli_tel'];
$VarDataNascimento = $_POST['cli_data_nasc'];
$VarCidade = $_POST['cli_cidade'];
$VarEstado = $_POST['cli_estado'];
$iniciaPerguntas = 1;
while($iniciaPerguntas <= $total_de_perguntas) {
$VarRespostas = $_POST["$iniciaPerguntas"];
$VarString = '$Query'.$iniciaPerguntas = "INSERT INTO sug_respostas (resp_fixa_id,
resp_fixa_id_perg,
resp_fixa_id_cliente,
resp_fixa_id_usu,
resp_fixa_id_resp,
resp_fixa_data)
VALUES (NULL,
'$iniciaPerguntas',
'$VarNewNumClientes',
'$VarUsuario',
'$VarRespostas',
'$VarDataCadastro');";
$Result = '$Result'.$iniciaPerguntas = $conn->query($VarString);
$iniciaPerguntas++;
}
Notice: Undefined index: in C: xampp htdocs general registration systems sugestoes salva.php on line 28
Notice: Undefined index: in C: xampp htdocs general registration systems sugestoes salva.php on line 28
Notice: Undefined index: in C: xampp htdocs general registration systems sugestoes salva.php on line 28
Notice: Undefined index: in C: xampp htdocs general registration systems sugestoes salva.php on line 28
Wouldn’t it be better to send the questions and answers in a single variable to treat this as Array in PHP? For example:
salva.php?...&respostas=1,3,2,0,3,1
where odd positions are the question id and pairs the id question answer to the left. After receiving the information, you can go through this array and record each question and its answer in the database.– Sam