Jump to content
xisto Community
Sign in to follow this  
PlugComputers

Help With Some Website Coding Databases and saving form results

Recommended Posts

Hey all, I was looking for some help with creating my new website. I have a form already created, with some text areas, checkboxes, drop down menu's, ect. I need some help setting up the code to save the form data once the user clicks "Submit" after filling in their information in the form.I was hoping to do this 2 ways - 1. Saving the information into some type of database (MySQL I'm guessing?) and 2. Have the form results emailed to me.I am familiar with the old way of emailing the results by putting "mailto:email@domain.com" into the form, but new browsers block against this, making it kind of a "shady" way of emailing the results in my opinion. Please help me, I need help coding it, and figuring out how to set up the database to accept the information from the form. Thanks again.

Share this post


Link to post
Share on other sites

well you could do what i would do and is use php and put all the contents in a text file and then write ANOTHER form just for you so you can read the information nice and orderly... or you could do this to make it email to you....

change the opening form tag to this:

<form action="formprocess.php" method="POST">

then create a php file called formprocess.php and put this in it:

<?$myemail = "youremail@host.com";$numoffields = "2";//YOU MUST CHANGE THIS$formn[0] = "What form 1 is called";$form[0] = $_POST['fieldname'];//field name is found in <input name=FIELDNAME>$formn[1] = "What form 2 is called";$form2[1] = $_POST['fieldname'];$message ="";for($i = 0; $i < $numoffields; $i++)$message .= $formn[$i] . " --- " . $form[$i] . "<br>";mail($myemail,"FORM RESULTS",$message);?>

its commented so you know what to do... just copy and paste this:
$formn[0] = "What form 1 is called";$form[0] = $_POST['fieldname'];

to where the other ones are and change the numbers accordingly

Share this post


Link to post
Share on other sites

a question to tsunamiwell i haven't googled this but i think you might already know it and the answer from you is much simpler then looking for some code on 20 pages :lol:the question is this..how to create the most simplest form that connects with a database?lets say you just have'Name''Text'and then something to display that information when asked (how to ask)?Well i'll be thankfull even if u just post a good link to some simple code :(

Share this post


Link to post
Share on other sites
download here

Readme.txt for the contact.php file++++++++++++++++++++++

This file contains the information required to set up and operate the contact.php script on your Web Host. Php capability is required for this script and the Php mail function must be available for the script to work as described. Even without the full use of the mail function, the data will be written to the message_data.txt file, so it is handier than it looks, even if you don't have full features available on your site.

There is also the option of displaying messages onto your site as a sort of 'Guest Book'.

The script is not 'independent'. The script must be added to a valid html page with a doctype, head tags, body tags, etc for this to be properly set-up. Or 'included' onto a php page which already contains the required tags.


Instructions
++++++++++++

1.) Use Winzip (or whatever you have) to unpack the zip files into a folder on your computer. (Kinda redundant, because you have already done that or you wouldn't be reading this file)

2.) Edit the file (contact.php) and change the following to better reflect your site requirements:
// site email
$site_email = 'someone@example.com';
// name of the site
$site_name = 'This Site Name';
// subject of emails as sent to the site-email
$site_subject = 'Message from Contact Form ';
// used to flag printing email messages below contact form
$show_comments = 'true';
// used to flag printing of site_email address on the message listing
$show_site_email = 'true';
// used to flag printing of site_name on the message listing
$show_site_name = 'true';
// name of the file where the messages are stored
$file_name = "message_data.txt";
// be sure to chmod the file to '666' (write enabled by all)
// only need to do the chmod if the error shows on a test run
$show_IP = '0'; // change this value to 1 to (show) the IP's on the displayed output
// default is $show_IP = '0' to (hide) the IP's

3.) Upload these files (contact.php and message_list.php) to your web server and place it into the directory which contains the file which calls the script. Typically, this would be "/public_html".

4.) set a link to this file from the other pages on your site. An example for the coding would be: <a href="contact.php" title="Use this page to send us an Email"> Email Us </a>

5.) Change the permissions for the "message_data.txt" file to "0666" to allow it to be written to. For a Windows Server, this step is not required. Enter a Sample Email and you will see an error message if this needs to be done for your Hosting Service.

When someone enters Form data, the script will store the information in the "message_data.txt" file and send you an email using the php mail() script. It requires all parts of the form to contain data, ie: first_name, last_name, email in a valid format, and a message body. The IP Address is gathered by the Server and it is also available to you. See below.

I have tested this using Mozilla, Opera and IE5.5, so it should work on pretty much any Browser. It works with the css shut-off, too. As for Hosts, I have it set-up on a Host using php 4.4.1 and php 5.0 both, so it should be good on most Hosting Services.

At present, the only way to access the data in the message.txt file is to reference it directly using an URL something like this:

"site; where site_name and Host_name match yours,

or by running the script to display the messages as follows:

"site;. (ditto)(Assuming the file is in the public_html Directory.)

In order to have access to the IP Address information, you either must change the value of the $show_IP variable before you run the script, (see item #2 above) (then change it back so it won't display on the Guest Book), or use the first option (site) to look at the file without the benefit of formatting or the Table Structure. Either way, I assure you the information will be there for you.


And if you have any difficulties with installing this script, just drop me a PM.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.