0
I’m doing an API and I’m going through a problem. When executing the script that calls the page via Curl, it does the insertion of a register in the database, but when it comes to registering only one record, it registers 2 equal.
Curl.php
<?php
$ch = curl_init();
$data = array('acao'=>'1', 'dados'=>array('nome'=>'Alisson Acioli', 'cpf'=>'xxxx', 'nascimento'=>date('Y-m-d'), 'email'=>'[email protected]', 'endereco'=>'xxx', 'bairro'=>'itaquera', 'estado'=>'SP', 'cidade'=>'São Paulo', 'referencia'=>'', 'nomemae'=>'Cecilia', 'cep'=>'08215255', 'endproprio'=>'1', 'nacionalidade'=>'Brasileiro', 'sexo'=>'Masculino', 'nomepai'=>'José Antonio', 'grau'=>'Ensino médio', 'estadocivil'=>'Casado', 'pessoafisica'=>'sim', 'login'=>'alisson', 'senha'=>'123456', 'natureza'=>'1'));
curl_setopt($ch, CURLOPT_URL, "http://localhost:8080/xxxx/api.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$output = curl_exec($ch);
echo $output;
curl_exec($ch);
?>
api.php
<?php
protected function CadastrarUsuario(){
$dados = $this->dados["dados"];
//echo json_encode($dados);
$condition = '';
foreach($dados as $colunm=>$row){
$condition .= '"'.$row.'"'.", ";
}
$condition = utf8_decode(substr($condition, 0, -2));
$insert = mysql_query("INSERT INTO cadastros VALUES (NULL, $condition)");
if($insert){
echo 'Registro inserido com sucesso!';
}else{
echo 'Erro ao realizar registro: '.mysql_error();
}
}
?>
Put the code where
CadastrarUsuario()
is called.– rray
public Function Executeaction(){ switch($this->acao){ case 1: $this->Sign up user(); break; case 2: echo 'Is the secondary action; break; } }
– Alisson Acioli
In the webserver log there are one or two Http requests for each Curl script run?
– gpupo
There is only one..
– Alisson Acioli