PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Dec 11, 2017 9:28 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed May 25, 2016 6:38 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4376
Location: United Kingdom
We use this for a client to export a list of users and their samples status.
But it's producing a ton of these:

Syntax: [ Download ] [ Hide ]
Notice: Use of undefined constant firstname - assumed 'firstname' in C:\xampp\phpMyAdmin\site\csv_NEWrequestssent.php on line 19


Syntax: [ Download ] [ Hide ]
<?php
session_start();
                if (isset($_SESSION["loggedin"]))
            {
            $usertype = $_SESSION["usertype"];
$id = isset($_GET['id']) ? $_GET['id'] : null;
if ($usertype == "admin" || $usertype == "moderator") {
include "dbconn.php";

$csv_output = '"Firstname","Lastname","House","Street","Town","County","Postcode","Product","Date Requested","Date Sent"';
$csv_output .= "\015\012";

$result = mysql_query("SELECT * FROM samples WHERE dateposted IS NOT NULL ORDER BY dateposted");
while($row = mysql_fetch_array($result))
{  
  $resultu = mysql_query("SELECT * FROM admin WHERE id = '$row[userid]'");
  while($rowu = mysql_fetch_array($resultu))
  {  
  $csv_output .= '"'.$rowu[firstname].'","'.$rowu[lastname].'","'.$rowu[address1].'","'.$rowu[address2].'","'.$rowu[town].'","'.$rowu[county].'","'.$rowu[postcode].'","'.$row[prodname].'","'.$row[dateadded].'","'.$row[dateposted].'"';
    $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=RequestsSent_" . date("Ymd") .".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=/'>";
        }
        ?>

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


Top
 Profile  
 
PostPosted: Wed May 25, 2016 7:31 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6402
Location: Montreal, Canada
Because you have undefined constants. Array keys need to be quoted when they're strings.

Syntax: [ Download ] [ Hide ]
$rowu[firstname]

should be
Syntax: [ Download ] [ Hide ]
$rowu['firstname']

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed May 25, 2016 8:32 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4376
Location: United Kingdom
Got it - thanks. Heaven knows how it worked before then.... coz it did.

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


Top
 Profile  
 
PostPosted: Wed May 25, 2016 8:39 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6402
Location: Montreal, Canada
It's bad practice, but should work regardless. PHP is able to figure out what you meant. Maybe a difference in PHP versions and/or error reporting levels? Either way, better to fix it.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed May 25, 2016 8:44 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4376
Location: United Kingdom
True. Learnt for next time. As I think I did raise this one before as well!

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


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

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 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