1
I have the following class in php:
<?php
class contaEntrada {
public $mostraDados;
public $insereDados;
function conectar(){
$host = "localhost";
$user = "root";
$pass = "root";
$dbname = "fluxo_de_caixa";
try {
$opcoes = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$pdo = new PDO("mysql:host=localhost;dbname=fluxo_de_caixa;", "root", "root", $opcoes);
} catch (Exception $e) {
echo $e->getMessage();
}
return $pdo;
}
function insereConta($id_empresa, $cat, $subcat, $val, $forPag, $data){
$pdo = conectar();
$val = floatval(str_replace(',', '.', str_replace('.', '', $val)));
if($data == ''){
$data = date("Y-m-d");
}
$this->insereDados->$pdo->prepare("INSERT INTO entrada (id_entrada, id_empresa, categoria, subcategoria, valor, forma_pagamento, data) VALUES (?, ?, ?, ?, ?, ?, ?)");
$this->insereDados->bindValue(1, NULL);
$this->insereDados->bindValue(2, $id_empresa);
$this->insereDados->bindValue(3, $cat);
$this->insereDados->bindValue(4, $subcat);
$this->insereDados->bindValue(5, $val);
$this->insereDados->bindValue(6, $forPag);
$this->insereDados->bindValue(7, $data);
$this->insereDados->execute();
}
<?
Then I call class and function:
<?php
require_once "con/conexao.php";
require_once "classes/contaEntrada.php";
$entrada = new contaEntrada();
$id_empresa = 1;
$cat = 1;
$subcat = 1;
$val = "100,00";
$forPag = "Blablabla";
$data;
$entrada->insereConta($id_empresa, $cat, $subcat, $val, $forPag, $data);
?>
However, when I run the function, the message "SERVER ERROR 500" appears on the screen. Can someone help me?
In the inseaccount function at the end has a
<?
is typing error? 500 error or blank screen is always programming error. Activate the errors, so add these two lines from at the beginning of the file,ini_set('display_errors', true); error_reporting(E_ALL);
Have other tips on php wiki besides this.– rray
This <? is a typo, because I didn’t put it in the code. .
– GustavoSevero
Now this two error warning appears: Notice: Trying to get Property of non-object in /Applications/MAMP/htdocs/systems/systems_web/fluxo_de_box/fluxojoin_v_hap/classes/contaEntrada.php on line 31 Fatal error: Call to a Member Funcprepare() on null in /Applications/MAMP/htdocs/systems/systems_web/fluxo_de_box/fluxojoin_v_hap/classes/accountEntrada.php on line 31
– GustavoSevero
$insereDados
does what? has the connection?– rray
Yes, see the code above. If that’s not what you’re asking, sorry, then I don’t get it
– GustavoSevero