Have a small web app that will input form data, and calculate 3 values based on query entered, pretty much just an aggregation of columns that meet specific criteria. The data enters in the database fine, but I'm trying to create a custom search that will set table variables according to selected date in query which is a php variable that is posted to the html form. I'm trying to use this post php variable as input for the date ranges in the search query. Currently am getting this error with $result
.
my 'action.php' file has the $conn object
<?php
include 'action.php';
$begindate = isset($_POST['start-date']) ? $_POST['start-date']: "";
$enddate = isset($_POST['end-date']) ? $_POST['end-date']: "";
$total =
"
SET @total = (SELECT sum(`fl_built`) FROM `records` where `date` = $begindate);
select @total as 'total_fl_built';
SET @qc = (select sum(`fl_qc`) from `records` where `date` = $enddate);
select @qc as 'total_qc_built';
SET @percent = round((@qc/@total) * 100);
select @percent as 'percentage';
"
$result = $conn->query($total);
echo "<table>";
if($result->num_rows>0){
while($row = $result->fetch_assoc()){
echo "<tr><td>" . $row['date'] . "</td><td>" . $row['hour'] . "</td><td>" . $row['pnp_kdt'] . "</td><td>" . $row['fl_built'] . "</td><td>" . $row['fl_qc'] . $row['total_fl_built'] . "</td><td>" . $row['total_fl_qc'] . "</td><td>" . $row['percentage'] . "</td><td>" . "</td></tr>" ;
}
}
echo "</table>";
$conn->close();
?>