<pre lang="text">
I am trying to configure "How to Import and Export CSV Files Using PHP and MySQL" by shahroze.nawaz@cloudways, using my database, but I keep getting this error:
Parse error: syntax error, unexpected 'else' (T_ELSE), expecting end of file in C:\xampp\htdocs\sql_download\functions.php on line 82. Below is the code from functions.php.
Any help would be greatly appreciated.
0)
{
$file = fopen($filename, "r");
while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
{
$sql = "INSERT into pos2020 (ospos_items.name,ospos_items.unit_price,ospos_receivings_items.quantity_purchased,ospos_items_taxes.percent,ospos_sales.sale_type) values ('".$getData[0]."','".$getData[1]."','".$getData[2]."','".$getData[3]."','".$getData[4]."')";
$result = mysqli_query($con, $sql);
// var_dump(mysqli_error_list($con));
// exit();
if(!isset($result))
{
echo "
alert(\"Invalid File:Please Upload CSV File.\");
window.location = \"index.php\"
";
}
else {
echo "
alert(\"CSV File has been successfully Imported.\");
window.location = \"index.php\"
";
}
}
fclose($file);
}
}
if(isset($_POST["Export"])){
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen("php://output", "w");
fputcsv($output, array('Product', 'Price', 'Qty', 'Tax', 'Paid By'));
$query = "SELECT * from pos2020 ORDER BY ospos_items.name";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_assoc($result)) {
fputcsv($output, $row);
}
fclose($output);
}
function get_all_records(){
$con = getdb();
$Sql = "SELECT * FROM pos2020";
$result = mysqli_query($con, $Sql);
if (mysqli_num_rows($result) > 0) {
echo "
";
}
while($row = mysqli_fetch_assoc($result)) {
echo "";
}
// echo "";
echo "
Product | Price | Qty | Tax | Paid By |
" . $row['ospos_items.name']." | " . $row['ospos_items.unit_price']." | " . $row['ospos_receivings_items.quantity_purchased']." | " . $row['ospos_items_taxes.percent']." | " . $row['ospos_sales.sale_type']." |
Export |
";
} else {
echo "you have no recent pending orders";
}
}
?>
What I have tried:
With my limited knowledge I have followed the code and compared it to the original. I have tried to contact shahroze.nawaz@cloudways the original author but no luck. Any help is very welcome.
Thank you