I have a function which performs an SQL query, "queryValue" the actual query to perform is passed later.
Function queryCreate($queryValue){
//DB connection variables
$host = "";
$user = "";
$password = "";
$database = "";
//create the connection
$conn = new mysqli($host, $user, $password, $database);
if ($conn->connect_error) {
die('DB Connection error: (' . $conn->connect_error . ') ' . $conn->connection_errorno);
}
$query = mysqli_query($conn,$queryValue) or die(mysqli_error($conn));
if ($result = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
fputcsv($fh, array_keys($result));
fputcsv($fh, $result);
while ($result = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
fputcsv($fh, $result);
}
}
return $queryValue;
}
I'm then attempting to assign the query value in a separate if statement. Below:
if(isset($_POST["Submit"]) && ($_POST['Weight'] == 'Weight')) {
$fh = csvCreate("Output Weight Null ".date('m-d-Y-His').".csv");
$queryValue = queryCreate('SELECT * FROM `table` WHERE WEIGHT = 0 OR weight IS NULL');
}
The problem I have is that the query does not appear to be being passed to the function. Could anyone suggest where I have gone wrong here? Many thanks.
The csvCreate function is shown here:
function csvCreate($filename){
header("Cache=Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$filename}");
header("Expires: 0");
header("Pragma: public");
$fh = @fopen( 'php://output', 'w' );
return $fh;
}