0
could you kindly help me with the following mistake:
Recoverable fatal error: Object of class Datetime could not be converted to string in C: xampp htdocs Portalpib query transactions.php on line 118.
I’m trying to return data from a table MySQL
in a table HTML
, but is returning the above error.
Follows code:
<?php
include("conexaobanco.php");
$datainicio = filter_input (INPUT_POST, "datainicio", FILTER_SANITIZE_STRING);
$datafim = filter_input (INPUT_POST, "datafim", FILTER_SANITIZE_STRING);
//$datainicio = DateTime::createFromFormat('d/m/Y',(filter_input (INPUT_POST, "datainicio", FILTER_SANITIZE_STRING)));
//$datafim = DateTime::createFromFormat('d/m/Y',(filter_input (INPUT_POST, "datafim", FILTER_SANITIZE_STRING)));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Portal Pib Cajamar</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
function editar() {
window.location.href = "edita_departamento.php";
}
function cadastrar() {
window.location.href = "membros.php";
}
function mask_date(field){
if(document.getElementById(field).value.length == 2){
document.getElementById(field).value = document.getElementById(field).value + "/";
}
if(document.getElementById(field).value.length == 5){
document.getElementById(field).value = document.getElementById(field).value + '/';
}
}
</script>
</head>
<body>
<br><br>
<div class="container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.php">Portal Pib Cajamar</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="login.php">Logout</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Secretaria
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="membros.php">Membros</a></li>
<li><a href="departamentos.php">Departamentos</a></li>
<li><a href="usuarios.php">Usuarios</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Tesouraria
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="transacoes.php">Transações</a></li>
<li><a href="conta.php">Contas</a></li>
</ul>
</li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</div>
</nav>
<br>
<h2>Membros Cadastrados</h2>
<br>
<form class="form-horizontal" method="post" action="consultatransacoes.php">
<div class="form-group">
<label class="control-label col-sm-2" for="datainicio">Data inicial:</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="datainicio" name="datainicio" onkeyup="mask_date(this.id);">
</div>
<label class="control-label col-sm-2" for="datafim">Data Final:</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="datafim" name="datafim" onkeyup="mask_date(this.id);">
</div>
<button type="submit" class="btn btn-success" text-align=center>Buscar</button>
</div>
<br>
</form>
<table class="table table-bordered">
<thead>
<tr>
<th>Data</th>
<th>Valor</th>
<th>Conta</th>
<th>Descrição</th>
<th>Editar</th>
<th>Excluir</th>
</tr>
</thead>
<tbody>
<?php
$sqlconsulta = mysqli_query($conn, "SELECT TB_TESOURARIA.*, date_format(TB_TESOURARIA.DATA, '%d/%m/%Y') as NEW_DATA FROM TB_TESOURARIA WHERE ID BETWEEN '".$datainicio."' AND '".$datafim."'");
while($dados=mysqli_fetch_assoc($sqlconsulta)){
?>
<tr>
<td><?php echo $dados['NEW_DATA'] ?></td>
<td><?php echo $dados['VALOR'] ?></td>
<td><?php echo $dados['CONTA'] ?></td>
<td><?php echo $dados['DESCRICAO'] ?></td>
<td><?php echo "<a href='edita_membros.php?id=" . $dados['ID'] . "'>Editar</a>" ?></td>
<td><?php echo "<a href='deleta_membros.php?id=" . $dados['ID'] . "'>Excluir</a>" ?></td>
<!--<td><buton type="button" class="btn btn-primary" onclick="editar()">Editar</buton></td>
<td><buton type="button" class="btn btn-danger">Excluir</buton></td>-->
<?php
}
?>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-block btn-success" text-align=center onclick="cadastrar();">Cadastrar usuário</button>
</div>
</body>
</html>
Good afternoon Maike, thank you very much for your return, but this I did straight from Select, see: $sqlconsulta = mysqli_query($Conn, "SELECT TB_TESOURARIA.*, date_format(TB_TESOURARIA.DATA, '%d/%m/%Y') as NEW_DATA FROM TB_TESOURARIA WHERE ID BETWEEN '". $datainicio." ' AND '". $datafim."'");
– Darezzo
Did you try to do it like I showed you? It worked?
– maiconfriedel
The error disappeared but does not return me information, I will give a var_dump and see the return
– Darezzo
is not returning anything, nor for the variable, var_dump returns NULL
– Darezzo
Doing the query in the database, which it returns?
– maiconfriedel
returns the correct values, I think the problem is in the return of the $datastart and $datafim variables, because if I run the application without it, the system normally fills the html tables
– Darezzo
Var_dump these two variables and see what returns
– maiconfriedel
Pera, that select
$SELECT TB_TESOURARIA.*, date_format(TB_TESOURARIA.DATA, '%d/%m/%Y') as NEW_DATA FROM TB_TESOURARIA WHERE ID BETWEEN '".$datainicio."' AND '".$datafim."'"
, where isWHERE ID BETWEEN '".$datainicio."' AND '".$datafim."'"
, is the ID column, would not be the date column?– maiconfriedel
'Cause I had checked it and I’ve already fixed it for date,...kkk...my fault but it still doesn’t work yet....
– Darezzo