They could kindly help me with the following error:
Recoverable fatal error: Object of class DateTime could not be converted to string in C: \ xampp \ htdocs \ PortalPib \ querytransactions.php on line 118.
I am trying to return data from a MySQL
table to a HTML
table, however it is returning the error above.
Following 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><scriptsrc="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>