PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Sep 19, 2019 2:21 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Apr 28, 2016 5:48 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
I have this script that
I get this error from the script below:

Syntax: [ Download ] [ Hide ]
Notice: Undefined variable: csv_output in C:\xampp\phpMyAdmin\site-2016\csv_vs.php on line 14

Notice: Use of undefined constant email - assumed 'email' in C:\xampp\phpMyAdmin\site-2016\csv_vs.php on line 14


Then I get loads of the "constant email" script error.

The field is named email. And the other fields are correct.

Syntax: [ Download ] [ Hide ]
$todaydate = date('Y-m-d');
include "dbconn.php";
$result = mysql_query("SELECT email FROM admin WHERE usertype = 'customer'");
while($row = mysql_fetch_array($result))
{      
  $csv_output .= '"'.$row[email].'"';
    $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=VS_EmailStore_" . date("Y-m-d") .".csv");
  print $csv_output;
  exit;
        mysql_close($sqlconn);
  echo "Extract in progress - one moment please...";

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Thu Apr 28, 2016 6:17 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
$csv_output isn't declared anywhere, so the first time you try to append to it, PHP is going to complain. The second notice is simply because you're referencing $row[email] rather than the correct $row['email']

_________________


Top
 Profile  
 
PostPosted: Thu Apr 28, 2016 2:51 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
1.
Syntax: [ Download ] [ Hide ]
header("Content-disposition: csv; filename=VS_EmailStore_" . date("Y-m-d") .".csv");

"csv" is not valid for the Content-Disposition. It is either "inline" to show in the browser or "attachment" to force a download.

Syntax: [ Download ] [ Hide ]
header("Content-disposition: attachment; filename=VS_EmailStore_" . date("Y-m-d") .".csv");


2.
Syntax: [ Download ] [ Hide ]
exit;
        mysql_close($sqlconn);
  echo "Extract in progress - one moment please...";

Nothing after the exit; will execute. It's the whole point of that command.

3. You cannot output messages like that as well as do the CSV download. Get rid of the message.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group