Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Posting Form data to HTML page
Closed Thread
Old 12-11-2007, 09:43 AM   #1 (permalink)
 
True Techie

Join Date: Nov 2003

Location: Minneapolis, MN

Posts: 157

kizzeith is on a distinguished road

Send a message via Yahoo to kizzeith
Default Posting Form data to HTML page

I'm trying to figure out how to POST data from an HTML form to an HTML. Basically, I want to create an easy way for multiple, non-coders to add information to a webpage.

The HTML form will contain a few fields and when it is submitted, I want the data to be added to the existing information on a seperate html page which can be viewed publicly.

My webhosting service allows php-scripting and MySQL, but I don't know how to use MySQL.

Any help would be greatly appreciated!
__________________
Gateway Machine - I know...I sold out...if I could do it over I'd have built like I used to
MS Vista Premium 32-bit
AMD Phenom (9500) Quad-core Processor 2.20 ghz
500GB hard drive
3GB DDR2 RAM
2 Free PCI-E slots x1
1 Free PCI-E x16
kizzeith is offline  
Old 12-11-2007, 12:44 PM   #2 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Posting Form data to HTML page

So, when your form is submitted you want it to create its own HTML page, containing only what they entered into the form?

There should be a place in your hosting somewhere to setup a MySQL database. Search your webhost's FAQ and you should find out how.

Post back with what exactly you want and I'll be happy to help.
__________________

Need website help? PM me!
CrazeD is offline  
Old 12-11-2007, 01:10 PM   #3 (permalink)
 
True Techie

Join Date: Nov 2003

Location: Minneapolis, MN

Posts: 157

kizzeith is on a distinguished road

Send a message via Yahoo to kizzeith
Default Re: Posting Form data to HTML page

Basically,

I want to have a page for weather-related cancellations that contains information entered into a POST form.

I want the info to collectively gather as it is entered.
__________________
Gateway Machine - I know...I sold out...if I could do it over I'd have built like I used to
MS Vista Premium 32-bit
AMD Phenom (9500) Quad-core Processor 2.20 ghz
500GB hard drive
3GB DDR2 RAM
2 Free PCI-E slots x1
1 Free PCI-E x16
kizzeith is offline  
Old 12-11-2007, 10:53 PM   #4 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Posting Form data to HTML page

Ok, if this isn't what you wanted let me know and I'll try to fix it.

mysql.php
This file is to set the host name, user name, password, and database name for your MySQL database (which you setup in your hosting somewhere).

PHP Code:
<?php

// Edit the content of these variables as needed
$host 'localhost'// This is the host, and is normally localhost
$user 'root'// This is the database username
$pass 'root'// This is the database password
$db   'dbname'// This is the database name itself

$connect = @mysql_connect ($host$user$pass) or die ('<b>ERROR:</b> Could not connect to database!');
$select  = @mysql_select_db ($db) or die ('<b>ERROR:</b> Could not select database!');

?>
enter.php
This file will enter the information from the form to the database

PHP Code:
<?php

require_once ('mysql.php');

if (isset (
$_POST['submit'])) {
        
// These next three variables get the information from the text fields
        // below
    
$field1 $_POST['field1'];
    
$field2 $_POST['field2'];
    
$field3 $_POST['field3'];

    if (!empty (
$field1) && !empty ($field2) && !empty ($field3)) {
        
$sql "INSERT INTO table_name (field_id, field1, field2, field3) VALUES (0, '".$field1."', '".$field2."', '".$field3."')";
        if (
$r mysql_query ($sql)) {
            echo 
'Your info has been entered successfully!';
        }
    } else {
        echo 
'You didn\'t fill out all the required fields, please try again!';
    }
} else {
    echo 
'<form action="enter.php" method="post">
    Field 1 <input type="text" name="field1" />
    <br />
    Field 2 <input type="text" name="field2" />
    <br />
    Field 3 <input type="text" name="field3" />
    <br />
    <input type="submit" name="submit" value="Submit" />
    </form>'
;
}

?>
view.php
This file will view the information in the database, ordered by newest to oldest

PHP Code:
<?php

require_once ('mysql.php');

$sql "SELECT * FROM table_name ORDER BY field_id DESC";
if (
$r mysql_query ($sql)) {
    
$num mysql_num_rows ($r);

    if (
$num 0) {
        echo 
'<table border="0" width="500px">
          <tr>
            <td align="center"><b>Field 1</b></td>
            <td align="center"><b>Field 2</b></td>
            <td align="center"><b>Field 3</b></td>
          </tr>'
;

          while (
$row mysql_fetch_array ($r)) {
              echo 
'<tr>
                <td align="center">'
.$row['field1'].'</td>
                <td align="center">'
.$row['field2'].'</td>
                <td align="center">'
.$row['field3'].'</td>
              </tr>'
;
          }

          echo 
'</table>';
    } else {
        print 
'There is no information yet.';
    }
}

?>
You will have to change "table_name" in both enter.php and in view.php to whatever you call your database table name.

I recommend taking a small, basic tutorial on MySQL so you are familiar with the terms and how everything works. It's not very complicated and can be learned quickly.

If this isn't what you wanted, I will try to change it so it is what you want. Let me know if you have any problems.
__________________

Need website help? PM me!
CrazeD is offline  
Old 12-12-2007, 11:27 AM   #5 (permalink)
 
True Techie

Join Date: Nov 2003

Location: Minneapolis, MN

Posts: 157

kizzeith is on a distinguished road

Send a message via Yahoo to kizzeith
Default Re: Posting Form data to HTML page

I definitely appreciate all of your help.

I am confused about how to upload this information on my server. I use dreamhost as my hosting service and haven't been able to figure out how to use the admin tool.

Can I just FTP the files?
__________________
Gateway Machine - I know...I sold out...if I could do it over I'd have built like I used to
MS Vista Premium 32-bit
AMD Phenom (9500) Quad-core Processor 2.20 ghz
500GB hard drive
3GB DDR2 RAM
2 Free PCI-E slots x1
1 Free PCI-E x16
kizzeith is offline  
Old 12-12-2007, 11:29 AM   #6 (permalink)
 
True Techie

Join Date: Nov 2003

Location: Minneapolis, MN

Posts: 157

kizzeith is on a distinguished road

Send a message via Yahoo to kizzeith
Default Re: Posting Form data to HTML page

It uses phpmyadmin
__________________
Gateway Machine - I know...I sold out...if I could do it over I'd have built like I used to
MS Vista Premium 32-bit
AMD Phenom (9500) Quad-core Processor 2.20 ghz
500GB hard drive
3GB DDR2 RAM
2 Free PCI-E slots x1
1 Free PCI-E x16
kizzeith is offline  
Old 12-15-2007, 03:38 AM   #7 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Posting Form data to HTML page

You have to make the files with the name I put above the code, and then put the code into the file. Of course, that is a very basic script because I didn't have specifics. If you want it more customized etc let me know.

Yes, you can just upload via FTP.

As for the PHPMyAdmin, sometimes you can't make actualyl create a database with it. Some hosts are different. There should be a support section with a FAQ or something showing how to make a MySQL database.

EDIT: Also make sure you make the necessary changes that I explained.
__________________

Need website help? PM me!
CrazeD is offline  
Old 12-18-2007, 12:03 PM   #8 (permalink)
 
True Techie

Join Date: Nov 2003

Location: Minneapolis, MN

Posts: 157

kizzeith is on a distinguished road

Send a message via Yahoo to kizzeith
Default Re: Posting Form data to HTML page

I created a db with a table and entered the host/login info to the mysql.php file. Also, I created fields in the table matching the field1, field 2, field 3 ID that is in the php script. I replaced table_name in both view/edit.php with my table name.

When I enter the info into edit.php, it gives me a blank white screen and no data is POSTed to the DB.

Any ideas why?
__________________
Gateway Machine - I know...I sold out...if I could do it over I'd have built like I used to
MS Vista Premium 32-bit
AMD Phenom (9500) Quad-core Processor 2.20 ghz
500GB hard drive
3GB DDR2 RAM
2 Free PCI-E slots x1
1 Free PCI-E x16
kizzeith is offline  
Old 12-19-2007, 07:39 AM   #9 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Posting Form data to HTML page

Make sure your submit button is named "submit".
__________________

Need website help? PM me!
CrazeD is offline  
Old 12-27-2007, 04:38 PM   #10 (permalink)
 
True Techie

Join Date: Nov 2003

Location: Minneapolis, MN

Posts: 157

kizzeith is on a distinguished road

Send a message via Yahoo to kizzeith
Default Re: Posting Form data to HTML page

Still can't get this thing to function properly, I think my table may be set up incorrectly.

I created a Database which the form seems to be able to access. I can tell this because when I enter an incorrect password in the mysql.php file it alerts me that it cannot access the db.

When I enter/submit the fields, nothing happens. The browser just blanks.

I have added the table name as: " INSERT INTO 'severeweather'.'cancel' but still no result. I have also tried just entering it as 'cancel' (without the 'severeweather'.)

There are 4 fields in the table, field_id, field1, field2, field 3.

Any idea where I should look? i know it's getting close, but it's not quite there.

I appreciate everything you've done thus far Crazed.

Thanks.
__________________
Gateway Machine - I know...I sold out...if I could do it over I'd have built like I used to
MS Vista Premium 32-bit
AMD Phenom (9500) Quad-core Processor 2.20 ghz
500GB hard drive
3GB DDR2 RAM
2 Free PCI-E slots x1
1 Free PCI-E x16
kizzeith is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML E-Mail Form (Outlook issue) Tempest Programming Discussions 2 11-24-2007 02:54 PM
Help - HTML form iorgus Programming Discussions 6 06-10-2007 03:01 PM