Good morning, I have the following query that makes me a query by dates to SQL SERVER:
$query="SELECT art_Clave, art_Costo, kar_Fecha, kar_Cantidad, kar_Origen, alma_Existencia FROM tArticuloKardex WHERE art_Clave='".$buscar."' AND (kar_Fecha BETWEEN '".$fecha1."' AND '".$fecha2."')";
$resultado=sqlsrv_query($conn, $query);
//se desplegaran los resultados en la tabla
echo "<table border=1>";
echo "<tr>";
echo "<th>SKU</th>";
echo "<th>COSTO</th>";
echo "<th>FECHA DE MOVIMIENTO</th>";
echo "<th>PIEZAS</th>";
echo "<th>TICKET</th>";
echo "<th>EXISTENCIA FINAL</th>";
echo "</tr>";
while($row=sqlsrv_fetch_array($resultado)){
echo '<tr>';
echo '<td>'.$row['art_Clave'].'</td>';
echo '<td>'.$row['art_Costo'].'</td>';
echo '<td>'.$row['kar_Fecha'].'</td>';
echo '<td>'.$row['kar_Cantidad'].'</td>';
echo '<td>'.$row['kar_Origen'].'</td>';
echo '<td>'.$row['alma_Existencia'].'</td>';
echo '</tr>';
}
echo "</table>";
And I pass the information to you by the following form:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST" name="buscar">
<input type="text" name="buscar" id="buscar" placeholder="Buscar:">
<input type="date" name="fecha1" id="fecha1">
<input type="date" name="fecha2" id="fecha2">
<input type="submit" name="enviar" value="Buscar">
</form>
And he sends me the following warning:
Warning: sqlsrv_fetch_array () expects parameter 1 to be resource, boolean given in C: \ xampp \ htdocs \ sana_php \ kardex.php on line 37 SKU COST DATE OF MOVEMENT PIECES TICKET FINAL EXISTENCE
They could help me. THANK YOU
I forgot, the data in the database is of the DateTime type and the way I pass through POST is the following:
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$buscar=filter_var($_POST['buscar'], FILTER_SANITIZE_STRING);
$fecha1=$_POST['fecha1'];
$fecha2=$_POST['fecha2'];
On the other hand, if I put it in the input as text instead of date, I get the following error:
Catchable fatal error: Object of class DateTime could not be converted to string in C: \ xampp \ htdocs \ sana_php \ kardex.php on line 41