/    Sign up×
Community /Pin to ProfileBookmark

Submit Form Info to Excel File

Hi all.

I’m having some trouble with saving my online form regristration information. I’d like to set it up so when the user fills in the fields and they click the submit button then information will automatically be saved in an excel file that will reside on the server. I’d like 2 fields: Name and email address. Hopefully some basic error checking can be included so they don’t leave fields blank etc.

Can anyone help me with this code. I’ve searched all over the net but have come up with nothing so far.

Thanks all,
Steve

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Feb 26.2007 — After search the web so much, you should've done one more search ?

http://www.webdeveloper.com/forum/search.php?searchid=2300711
Copy linkTweet thisAlerts:
@BarnieauthorFeb 26.2007 — Unfortunately the link doesn't work ? but I will try searching this site again.
Copy linkTweet thisAlerts:
@NightShift58Feb 26.2007 — I had searched on "export excel" in "php" forum.

The 8th or 10th item is the one you're looking for...
Copy linkTweet thisAlerts:
@BarnieauthorFeb 26.2007 — Is this the one you mean? If so would you be able to explain where I need to put this and what I need to modify. Sorry I know you've heard this all before but I do appreciate it. I'm a total newb when it comes to this.

Thanks

http://www.webdeveloper.com/forum/showthread.php?t=95341&highlight=export+excel
Copy linkTweet thisAlerts:
@NightShift58Feb 26.2007 — I'd forgotten this one: http://www.webdeveloper.com/forum/showpost.php?p=714115&postcount=10

by member Bokeh. He's still learning ? but his stuff tends to works.

Of course, he using a SQL query in the example, so you would have to amend that to use your POST array, but the basic method should apply.
Copy linkTweet thisAlerts:
@bokehFeb 26.2007 — The privous link just produces a tab delimited file. For a real excel file try this: http://www.webdeveloper.com/forum/showpost.php?p=714115&postcount=10[B]



Edit:[/B]
Nightshift beat me to it. Note: there are two different functions there, one to output to the browser and the other to create a file.
Copy linkTweet thisAlerts:
@NightShift58Feb 26.2007 — Nightshift beat me to it.[/QUOTE]This late-night hacking is doing you in...
Copy linkTweet thisAlerts:
@BarnieauthorFeb 26.2007 — So this is in the one I need correct? Where do I put this code? Yeah I'm totally lost ?

function XLSFile($query, $file)

{

/*******************************************************

FUNCTION NAME:
XLSFile

AUTHOR:
bokeh

PURPOSE:
To create an Excel (.XLS) format file from any valid
database query.

DESCRIPTION:
bool XLSFile( string query, string file )

INPUTS:
$query (string) should be a valid MySQL query.
$file (string) is the file (including the path)to
which the Excel formatted data should be saved. A
database connection must exist before calling this
function.

RETURN VALUE:
Boolean, true on success, false otherwise.

*********************************************************/

$query_result = mysql_query($query) or
trigger_error("Function <b>RealXLSFile</b>: MySQL error, " . mysql_error(), E_USER_ERROR);
if(mysql_num_rows($query_result))
{
$fh = @fopen($file, 'w+') or
trigger_error('Function <b>RealXLSFile</b>: file could not be created (permissions problem).', E_USER_ERROR);
fwrite($fh, pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0));
$first_time = true;
$XLSrow = 0; $XLScol = 0;
while($row = mysql_fetch_assoc($query_result))
{
if($first_time)
{
$first_time = false;
$headings = array_keys($row);
foreach($headings as $heading)
{
fwrite($fh, pack("ssssss", 0x204, 8+($L = strlen($heading)), $XLSrow, $XLScol++, 0x0, $L).$heading);
}
}
$XLScol=0; ++$XLSrow;
foreach($headings as $heading)
{
if(is_numeric($row[$heading]))
{
fwrite($fh, pack("sssss", 0x203, 14, $XLSrow, $XLScol++, 0x0).pack("d", $row[$heading]));
}
else
{
fwrite($fh, pack("ssssss", 0x204, 8 + ($L = strlen($row[$heading])), $XLSrow, $XLScol++, 0x0, $L).$row[$heading]);
}
}
}
fwrite($fh, pack("ss", 0x0A, 0x00));
fclose($fh);
return true;
}
return false;

}

function XLSOutput($query, $filename = null)

{
Copy linkTweet thisAlerts:
@BarnieauthorFeb 27.2007 — Thanks all. I was able to get a friend to give me a hand with it. I do appreciate all the help.

Thanks again NightShift58 and Boken ?
×

Success!

Help @Barnie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...