0
I want to do more than 1 Insert using PDO and a php file, can I? Example:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type,X-Prototype-Version,X-Requested-With');
date_default_timezone_set('America/Sao_Paulo');
include_once("conPDO.php");
$pdo = conectar();
$data = file_get_contents("php://input");
$data = json_decode($data);
$msg = $data->msg;
$idUsuario = $data->idUsuario;
$idCep = $data->idCep;
$nome = $data->nome;
$foto ='';
$qryEnd=$pdo->prepare("SELECT * FROM cep WHERE idCep=:idCep");
$qryEnd->bindValue("idCep", $idCep);
$qryEnd->execute();
while ($linha=$qryEnd->fetch(PDO::FETCH_ASSOC)) {
$idCep = $linha['idCep'];
$uf = $linha['uf'];
$cidade = utf8_encode($linha['cidade']);
$bairro = utf8_encode($linha['bairro']);
$logradouro = utf8_encode($linha['logradouro']);
}
$data = date('Y-m-d,H:m:s');
$diaEHora = explode(',', $data);
$data = $diaEHora[0];
$hora = $diaEHora[1];
$insereMsgLogra=$pdo->prepare("INSERT INTO avisosLogradouro (idAvisoLogradouro, idUsuario, estado, cidade, bairro, logradouro, msg, foto, data, hora) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$insereMsgLogra->bindValue(1, NULL);
$insereMsgLogra->bindValue(2, $idUsuario);
$insereMsgLogra->bindValue(3, $uf);
$insereMsgLogra->bindValue(4, $cidade);
$insereMsgLogra->bindValue(5, $bairro);
$insereMsgLogra->bindValue(6, $logradouro);
$insereMsgLogra->bindValue(7, $msg);
$insereMsgLogra->bindValue(8, $foto);
$insereMsgLogra->bindValue(9, $data);
$insereMsgLogra->bindValue(10, $hora);
$insereMsgLogra->execute();
$insereMsgBairro=$pdo->prepare("INSERT INTO avisosBairro (idAvisoBairro, idUsuario, estado, cidade, bairro, msg, foto, data, hora) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$insereMsgBairro->bindValue(1, NULL);
$insereMsgBairro->bindValue(2, $idUsuario);
$insereMsgBairro->bindValue(3, $uf);
$insereMsgBairro->bindValue(4, $cidade);
$insereMsgBairro->bindValue(5, $bairro);
$insereMsgBairro->bindValue(6, $msg);
$insereMsgBairro->bindValue(7, $foto);
$insereMsgBairro->bindValue(8, $data);
$insereMsgBairro->bindValue(9, $hora);
$insereMsgBairro->execute() or die(print_r($insereMsgBairro->errorInfo());
?>
Is it possible to do that? 'Cause I tried and only the first one worked.
In the php log shows this:
[01-Feb-2016 19:49:09 Europe/Berlin] PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be Removed in a Future version. To avoid this Warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream Instead. in Unknown on line 0
Yes it is possible, there are no limits for PDO :D
– rray
See what is the error of the second Insert, maybe it is violation of some Uniq key field.
– rray
How I see PDO errors?
– GustavoSevero
Makes,
$insereMsgBairro->execute() or die(print_r($insereMsgBairro->errorInfo());
– rray
Beauty @rray, I’ll try
– GustavoSevero
Look, the error you gave was this: http://localhost:8888/systems/system_web/Ionic/vcApp/www/php/enviaMsgLogra.php 500 (Internal Server Error) Apparently it’s an error in my php code
– GustavoSevero
Yes, puts
ini_set('display_errors', true); error_reporting(E_ALL);
at the beginning of this file.– rray
I already have it in my code
– GustavoSevero
Only by the log of the apache there.
– rray
In the apache log I did not find, but php did. .
– GustavoSevero
Put as text that is easier to read, this is the complete code?
– rray
Sorry, but how so, put as text? No, have other selects to fetch other data, tb
– GustavoSevero
The error is like an image, I can’t see.
– rray
Ahh yes, it’s a print I took... I’ll change it then
– GustavoSevero
@rray, put the error message, log, text, post
– GustavoSevero
I think I found the mistake...
– GustavoSevero
I thought it was a mistake, but that wasn’t the problem
– GustavoSevero
Fixed this: $inserts MsgBairro->execute() or die(print_r($Pdo->errorInfo()); Left to close 1 parenthesis
– GustavoSevero