CSV Export - why the undefineds??
Posted: Wed Sep 03, 2014 6:14 am
I have this script that works on another site with no errors, like this:
But this version, looking on a different DB, where all fields do have data, is erroring:
[text]Notice: Use of undefined constant firstname - assumed 'firstname' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
Notice: Use of undefined constant lastname - assumed 'lastname' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
Notice: Use of undefined constant email - assumed 'email' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
Notice: Use of undefined constant password - assumed 'password' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
Notice: Use of undefined constant type - assumed 'type' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
[/text]
100s of times over... and then it shows the results, but NOT with a CSV export. It does it only on screen.
Code: Select all
<?php
$cookietype = isset($_COOKIE['type']) ? $_COOKIE['type'] : null;
$todaydate = date('Y-m-d');
$catid = isset($_REQUEST['catid']) ? $_REQUEST['catid'] : null;
if ($cookietype == "admin") {
include "dbconn.php";
$csv_output = '"Product ID","Product","Romancode","Category"';
$csv_output .= "\015\012";
$result = mysql_query("SELECT id, title, romancode, catname FROM products WHERE rcstock = 'out of stock' AND catid = '$catid'");
while($row = mysql_fetch_array($result))
{
$csv_output .= '"'.$row[id].'","'.$row[title].'","'.$row[romancode].'","'.$row[catname].'"';
$csv_output .= "\015\012";
}
//You cannot have the breaks in the same feed as the content.
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv; filename=SoldOutProducts_" . date("d-m-Y") .".csv");
print $csv_output;
exit;
mysql_close($sqlconn);
echo "Extract in progress - close page when completed.";
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=/'>";
}
?>Code: Select all
<?php
$cookietype = isset($_COOKIE['type']) ? $_COOKIE['type'] : null;
if ($cookietype == "admin") {
include "dbconn.php";
$csv_output = '"Firstname","Lastname","Email","Password"';
$csv_output .= "\015\012";
$result = mysql_query("SELECT firstname, lastname, email, password, `type` FROM admin WHERE `type` <> 'admin'");
while($row = mysql_fetch_array($result))
{
$csv_output .= '"'.$row[firstname].'","'.$row[lastname].'","'.$row[email].'","'.$row[password].'","'.$row[type].'"';
$csv_output .= "\015\012";
}
//You cannot have the breaks in the same feed as the content.
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv; filename=SoldOutProducts_" . date("d-m-Y") .".csv");
print $csv_output;
exit;
mysql_close($sqlconn);
echo "Extract in progress - close page when completed.";
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=/'>";
}
?>Notice: Use of undefined constant lastname - assumed 'lastname' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
Notice: Use of undefined constant email - assumed 'email' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
Notice: Use of undefined constant password - assumed 'password' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
Notice: Use of undefined constant type - assumed 'type' in C:\xampp\phpMyAdmin\site\csv_users.php on line 14
[/text]
100s of times over... and then it shows the results, but NOT with a CSV export. It does it only on screen.