473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Saving a form to the server

There has to be a name for what I want to do and I don't know what words
to google for.

I have a form here:
http://www.texasflyfishers.org/firstpage.htm

I want to submit it to the server and have it saved:
1. In a directory by the guides name which would be the variable
'describe11'. Create this directory if it does not already exist.
2. Create a special file name from the date and time submitted.

This form will be filled out by a bunch that are not very computer
literate, so I must automate everything for them.

I've been searching/googling for 3 weeks now with little to no success.
Can anyone help?

TIA
Dave
--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.
May 13 '07 #1
7 1950
On May 13, 9:48 am, Dave Kelly <daveeke...@earthlink.netwrote:
There has to be a name for what I want to do and I don't know what words
to google for.

I have a form here:http://www.texasflyfishers.org/firstpage.htm

I want to submit it to the server and have it saved:
1. In a directory by the guides name which would be the variable
'describe11'. Create this directory if it does not already exist.
2. Create a special file name from the date and time submitted.

This form will be filled out by a bunch that are not very computer
literate, so I must automate everything for them.

I've been searching/googling for 3 weeks now with little to no success.
Can anyone help?

TIA
Dave
--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.
At the moment, that website is down. Based on your description, I
think I can guess at what you need though.

When you submit a form to a PHP page, that PHP script can access the
data that's in the form through the $_REQUEST superglobal array. You
can be more specific and use either $_GET or $_POST, which correspond
to the method attribute on the HTML form tag. You most likely want to
use the POST method to keep the url looking clean. You can just use
$_REQUEST no matter what method you use. If you change you mind later,
you can just change the HTML form tag.

So here's an example of how to use your superglobals:

<?php // this is whatever.php
if( isset( $_REQUEST['submitBtn'] ) )
{
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];

//do something with those variables...
}
?>
<html><head><title>myform</title></head><body>
<form id="myForm" method="post" action="whatever.php">
<label for="name">Name</label><br />
<input type="text" id="name" /><br /><br />

<label for="email">Email</label><br />
<input type="text" id="email" /><br /><br />

<input type="submit" id="submitBtn" value="submit" />
</form>
</body></html>

Now you have your data, and what you do next depends on what kind of
data it is. You should probably save it into a database. Databases are
designed to make it easier to store and retrieve data. If you don't
have access to a database, then it's ok to just use flat files as you
mentioned. The data is easier to store than retrieve with flat files.

Here's what you can do with those variables in the body of the
conditional (to save in files):

<?php
$baseDir = 'stuff';
if( !is_dir( "$baseDir/$describe11" ) )
mkdir( "$baseDir/$describe11" );
$filename = time()."|{$_REQUEST['name']}.dat";
file_put_contents( "$baseDir/$describe11/$fileName",
serialize( $_REQUEST ) );
?>

Let's assume you made $_REQUEST['name'] and $describe11 safe for the
file system. The above will put the form data into a file in /stuff/
<guide>/<time>|<name>.dat.

Here's another simple example to retrieve the data with another file:

<?php // read.php
$baseDir = 'stuff';
$guide = isset( $_REQUEST['guide'] )
? $_REQUEST['guide']
: 'defaultguide';

$stuff = dir( "$baseDir/$guide" );
while( false !== ( $item = $stuff->read() ) )
{
if( !preg_match( '#([0-9]+)\|(.*)\.dat#i', $item, $info ) )
continue;

$data = unserialize( file_get_contents( "$baseDir/$guide/$item" ) );

echo "Time: {$info[1]}<br />Name: {$info[2]}<br />Data:<br />",
str_replace( "\n", '<br />', str_replace( ' ', '&nbsp;',
$data ) ),
'<br /><br />';
}
?>

You would be able to list all submissions associated with a guide by
adding ?guide=<guidenameto the end of the url. You should make that
variable safe for the file system before using it, though.

-Mike PII

May 13 '07 #2
Mike P2 wrote:
On May 13, 9:48 am, Dave Kelly <daveeke...@earthlink.netwrote:
At the moment, that website is down. Based on your description, I
think I can guess at what you need though.
Thanks for the long and detailed response. Appreciate the help.
I can't comment until I wade through all you said.

About the site being down.
Your timestamp was 12:34, at 1:25 it was up. This happens quite a lot.
Even to me. Wish I knew why.

D

--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.
May 13 '07 #3
Mike P2 wrote:
?>

Let's assume you made $_REQUEST['name'] and $describe11 safe for the
file system.
?>
You should make that
variable safe for the file system before using it, though.
To isolate a question. I have searched for make variable safe and this
is what I found. Is this what you intended by the above statements?

<?php //quote-smart.php
// Quote variable to make safe
function quote_smart($value) {
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value) || $value[0] == '0') {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
?>
--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.
May 13 '07 #4
On May 13, 7:26 pm, Dave Kelly <daveeke...@earthlink.netwrote:
Mike P2 wrote:
?>
Let's assume you made $_REQUEST['name'] and $describe11 safe for the
file system.
?>

You should make that
variable safe for the file system before using it, though.

To isolate a question. I have searched for make variable safe and this
is what I found. Is this what you intended by the above statements?

<?php //quote-smart.php
// Quote variable to make safe
function quote_smart($value) {
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value) || $value[0] == '0') {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;}

?>

--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.
That function is for making data safe to insert it into the database.
What I meant was to strip out forward slashes and backslashes, because
otherwise they could put in a name that would make a file path that's
not where you want it to be.

If they put a slash in it, PHP might think it means the first part is
a folder.

-Mike PII

May 13 '07 #5
Mike P2 wrote:
On May 13, 7:26 pm, Dave Kelly <daveeke...@earthlink.netwrote:
>Mike P2 wrote:
>>?>
Let's assume you made $_REQUEST['name'] and $describe11 safe for the
file system.
?>
You should make that
>>variable safe for the file system before using it, though.
To isolate a question. I have searched for make variable safe and this
is what I found. Is this what you intended by the above statements?

<?php //quote-smart.php
// Quote variable to make safe
function quote_smart($value) {
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value) || $value[0] == '0') {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;}

?>

--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.

That function is for making data safe to insert it into the database.
What I meant was to strip out forward slashes and backslashes, because
otherwise they could put in a name that would make a file path that's
not where you want it to be.

If they put a slash in it, PHP might think it means the first part is
a folder.

-Mike PII
Does this not take care of that?

// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.
May 14 '07 #6
Dave Kelly wrote:
Mike P2 wrote:
>On May 13, 7:26 pm, Dave Kelly <daveeke...@earthlink.netwrote:
>>Mike P2 wrote:
?>
Let's assume you made $_REQUEST['name'] and $describe11 safe for the
file system.
?>
You should make that

variable safe for the file system before using it, though.
To isolate a question. I have searched for make variable safe and this
is what I found. Is this what you intended by the above statements?

<?php //quote-smart.php
// Quote variable to make safe
function quote_smart($value) {
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value) || $value[0] == '0') {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;}

?>

--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.

That function is for making data safe to insert it into the database.
What I meant was to strip out forward slashes and backslashes, because
otherwise they could put in a name that would make a file path that's
not where you want it to be.

If they put a slash in it, PHP might think it means the first part is
a folder.

-Mike PII

Does this not take care of that?

// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
Nope, it only does it if get_magic_quotes_gpc returns true.

The basic rule of thumb about making data safe (at least for textual
representations) is use stripslashes on it anyway.

Granted, the rule of thumb is "make data safe/never trust user input."

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 14 '07 #7
On May 13, 9:22 pm, Dave Kelly <daveeke...@earthlink.netwrote:
Mike P2 wrote:
On May 13, 7:26 pm, Dave Kelly <daveeke...@earthlink.netwrote:
Mike P2 wrote:
?>
Let's assume you made $_REQUEST['name'] and $describe11 safe for the
file system.
?>
You should make that
>variable safe for the file system before using it, though.
To isolate a question. I have searched for make variable safe and this
is what I found. Is this what you intended by the above statements?
<?php //quote-smart.php
// Quote variable to make safe
function quote_smart($value) {
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value) || $value[0] == '0') {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;}
?>
--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.
That function is for making data safe to insert it into the database.
What I meant was to strip out forward slashes and backslashes, because
otherwise they could put in a name that would make a file path that's
not where you want it to be.
If they put a slash in it, PHP might think it means the first part is
a folder.
-Mike PII

Does this not take care of that?

// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}

--
That's still related to apostrophes and the database. stripslashes()
replaces \' with ', which is supposed to undo addslashes() which does
the opposite.

What I'm talking about is something like this:

$var = str_replace( array( '/', '\\' ), '-', $var );

That should remove slashes that might confuse the file system into
thinking there's another folder there.

By the way, if you are inserting stuff into a MySQL database, you
should use the appropriate real_escape_string() function instead of
addslashes(). For example, if you are using the normal MySQL
extension, use the mysql_real_escape_string() function to escape crap
that can confuse MySQL. There's other stuff than just apostrophes and
backslashes that should be escaped for MySQL.

-Mike PII

May 14 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kevin Ingram | last post by:
Ok, this is probably a silly question but I just keep hitting a brick wall here. I usually develop my sites entirely in ASP and use a database for data storage, works great for me. I also...
0
by: Umesh | last post by:
Hi, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this stream as a...
1
by: John | last post by:
(access 2002) Anyone have any suggestions as to what may be causing access to not save form changes after I "tell" it to, exit database, then re-open later to discover the changes had not been...
0
by: mathieu cupryk | last post by:
in the Button1_Click I need to make the 1st column saved as readonly. How can I do this? using System; using System.Collections; using System.ComponentModel; using System.Data; using...
0
by: Luis Esteban Valencia | last post by:
in the Button1_Click I need to make the 1st column saved as readonly. How can I do this? using System; using System.Collections; using System.ComponentModel; using System.Data; using...
3
by: RCS | last post by:
I have an app that I have different "sections" that I want to switch back and forth from, all while having the server maintain viewstate for each page. In other words, when I am on Page1.aspx and...
0
by: Umesh | last post by:
Hi Gurus, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
11
by: Kevin | last post by:
I've been searching forever for examples of saving data changes in a DataGridView. There's all kinds of examples, but none really show how to save changes. Someone please help me. I have a...
3
by: pozze | last post by:
Hi, I've just made the change from ASP to .net. I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.