By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,190 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,190 IT Pros & Developers. It's quick & easy.

Mail Fields To Database. Exportable...any ideas?

P: n/a
Hey, intermediate php/mysql user here. I have a mailing list form on
my website, what i'd ultimately like to happen is when the user
submits their information that all goes into the database. The tricky
part is i'd like it so for my clients, they can go to an admin utility
and press an "export" button and have it spit out the data from that
form, into either an excel doc or a csv, whatever is easiest... any
suggestions on how to do this?

Truck

May 22 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Truck Estevez <oo******@gmail.comwrites:
Hey, intermediate php/mysql user here. I have a mailing list form on
my website, what i'd ultimately like to happen is when the user
submits their information that all goes into the database. The tricky
part is i'd like it so for my clients, they can go to an admin utility
and press an "export" button and have it spit out the data from that
form, into either an excel doc or a csv, whatever is easiest... any
suggestions on how to do this?

Truck
Hi Truck,

This should be quite simple if you go with csv.
Basically, you just send to content of your document
to the client just like you would a webpage, the key
is setting the correct headers so that the browser
knows what to do with it.

Take a look at the php docs for the header() function.
http://php.net/header

I think you'll want to start by setting the "content-type",
"content-length" and "content-disposition". You may also
need to set others depending on the browser.

Hope that helps,
Carl.
May 22 '07 #2

P: n/a
Truck Estevez wrote:
Hey, intermediate php/mysql user here. I have a mailing list form on
my website, what i'd ultimately like to happen is when the user
submits their information that all goes into the database. The tricky
part is i'd like it so for my clients, they can go to an admin utility
and press an "export" button and have it spit out the data from that
form, into either an excel doc or a csv, whatever is easiest... any
suggestions on how to do this?

Truck
Truck,

As Carl indicate, CSV should be quite easy.

However - I'd advise against this. People signed up to receive mail
from YOUR site. Suddenly getting mail from other sites would probably
be reported as spam - and you're client would be very upset if he got
labeled as a spammer for using your mailing list.

And there's no recourse. Yes, this is an opt-in mailing list (double
opt-in, I hope!). But the opt-in was not to receive mail from anyone
you sell your list to.

It will also get you in trouble with people who signed up on your opt-in
list.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 23 '07 #3

P: n/a
Jerry Stuckle wrote:
However - I'd advise against this. People signed up to receive mail
from YOUR site. Suddenly getting mail from other sites would probably
be reported as spam - and you're client would be very upset if he got
labeled as a spammer for using your mailing list.
I'd assumed that when the OP referred to "my website" he meant, "the
website I'm building for my client". Though I could be wrong.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 88 days, 14:20.]

The Great Wi-Fi Controversy
http://tobyinkster.co.uk/blog/2007/05/22/wifi-scare/
May 23 '07 #4

P: n/a
Toby A Inkster wrote:
Jerry Stuckle wrote:
>However - I'd advise against this. People signed up to receive mail
from YOUR site. Suddenly getting mail from other sites would probably
be reported as spam - and you're client would be very upset if he got
labeled as a spammer for using your mailing list.

I'd assumed that when the OP referred to "my website" he meant, "the
website I'm building for my client". Though I could be wrong.
Hi, Toby,

That could be. I'm going on his wording - he mentioned "my website" and
"my clients" in a way which looked to me to be referring to two
different things. But I could be wrong, also.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 23 '07 #5

P: n/a
I actually meant it solely for the client and no one else... moving on
though, I did find an export to excel script but i'm having one
problem: the php displays all the data fine in text form, but a file
download prompt is also supposed to pop up and this isn't happening.
Any ideas why?

Here's the code:
<?php

$user="user";
$host="localhost";
$password="pass";
$database = "db";
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
if ($db = mysql_select_db($database,$connection))
echo"connection successful";

if (check_valid_user_admin())
{

$select = "SELECT * FROM mailinglist";
$export = mysql_query($select);
$fields = mysql_num_fields($export);

while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value)
{
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\are","",$data);

if ($data == "") {
$data = "\n(0) Records Found!\n";
}

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=dorado.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>

Like I said, it displays the data fine, just no download prompt which
is a bummer. Any ideas?

Truck

May 23 '07 #6

P: n/a
Truck Estevez wrote:
I actually meant it solely for the client and no one else... moving on
though, I did find an export to excel script but i'm having one
problem: the php displays all the data fine in text form, but a file
download prompt is also supposed to pop up and this isn't happening.
Any ideas why?

Here's the code:
OK, glad it's for only this client.

You don't get the popup because you have your browser set up to handle
the application/x-msdownload by default. There isn't anything you can
do about browser settings from the server end.

<snip>
>
Like I said, it displays the data fine, just no download prompt which
is a bummer. Any ideas?

Truck
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 24 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.