2
How do I create a function, in Factory, to enter data in the database? I have it:
.factory('pegaContas', ['$http', function($http) {
var _getContasEntrada = function(id_empresa) {
return $http.post("php/index.php", id_empresa);
};
var _setContasEntrada = function(conta) {
}
return {
getContasEntrada: _getContasEntrada
setContasEntrada: _setContasEntrada
}
}])
And my function/method in php
data insertion is in a class:
<?php
function insereContaEntrada($id_empresa, $cat, $subcat, $val, $forPag, $data){
$pdo = conectar();
$val = floatval(str_replace(',', '.', str_replace('.', '', $val)));
if($data == ''){
$data = date("Y-m-d");
}
$this->insereDadosEntrada=$pdo->prepare(
"INSERT INTO entrada (id_entrada, id_empresa, categoria, subcategoria, valor, forma_pagamento, data)
VALUES (?, ?, ?, ?, ?, ?, ?)");
$this->insereDadosEntrada->bindValue(1, NULL);
$this->insereDadosEntrada->bindValue(2, $id_empresa);
$this->insereDadosEntrada->bindValue(3, $cat);
$this->insereDadosEntrada->bindValue(4, $subcat);
$this->insereDadosEntrada->bindValue(5, $val);
$this->insereDadosEntrada->bindValue(6, $forPag);
$this->insereDadosEntrada->bindValue(7, $data);
//$this->insereDadosEntrada->execute();
try {
$this->insereDadosEntrada->execute();
echo "Cadastro efetuado com sucesso!";
} catch (Exception $e) {
print_r($this->insereDadosEntrada->errorInfo());
}
}
?>
I want to call that method at the angle.
Thanks, I’ll try it...
– GustavoSevero
@Gustavosevero edited my answer. As you are using php, often the error is not in Angular, so I recommend using Factory’s Return in that way, so you can see in the console what is happening in php.
– celsomtrindade
Right..........
– GustavoSevero
Nothing goes inside this: var _setContasEntrate = Function(account) { }; ?
– GustavoSevero
I think not, these functions have no relation to each other. The _setContasEntrate function would be used to call another php function. If not your case, it can be deleted
– celsomtrindade