GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Aug-2006, 21:25
vigilantweather vigilantweather is offline
New Member
 
Join Date: Feb 2006
Posts: 28
vigilantweather is on a distinguished road
Exclamation

HTML Form to PHP File - Help Requested


Hi everyone,

I have a fairly small knowledge of PHP scripting, but I know what I want to do here.

I want to take an HTML form and post the data to a PHP file. I will explain:

I am working on a whole new part of my site and it would be a great addition to it; anyway... I would like to have an HTML file with an HTML form in it. This form would contain several fields that would then need to be transported to a PHP file.


I would like for the PHP file to show the data entered into the form. And I am not talking about showing the user who entered the information in, I'm talking about posting the data to the public on the page (the page will be in my site design using frames or something similar).

Is there a way to keep that data shown to everyone (the public)?

And if so, is there a way to erase the data after a given number of hours. This is going to be a user-defined weather alert post page. The user can set expiration times/dates with a specificed number of hours.

Could someone please help me with the scripting of the PHP file, and also anything to connect the HTML form to the PHP file, such as "<form action" which I will need to know.

Please help me out, this would be a great addition and I can't wait to inform everyone of important weather information (it will be collaborative, that is why I'm using forms).

Please reply as soon as possible, any help is truly appreciated!! Thanks in advance!
  #2  
Old 06-Aug-2006, 21:32
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: HTML Form to PHP File - Help Requested


I just came across an interesting read about some of what you're asking about here:
http://www.webmonkey.com/99/21/index2a.html

You could probably jump right into 'Lesson 2' topics (there's a link on the left-hand side of the page).

Post back if there may be other need(s).
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 06-Aug-2006, 21:39
vigilantweather vigilantweather is offline
New Member
 
Join Date: Feb 2006
Posts: 28
vigilantweather is on a distinguished road
Exclamation

Re: HTML Form to PHP File - Help Requested


Thanks for the link ... I already have MySQL and PHP installed. My main site would not run without either (see vigilantweather.com). I am going to hopefully branch it off in a different directory, away from the main site. I would never think to use a database with my situation here... do you have any information?

I am thinking about saving the results for a specificed time period and showing everyone the results for that time period.

Example:

User clicks on Boston weather office (this is how it will be set up), sees a 'weather discussion' (or whatever made in the HTML form) issued and the person that sent in the form set the alert to expire in 4 hours... then in 4 hours it is taken off automatically. But the thing is, we need the public to see all of this for those 4 hours and then for it to be removed after 4 hours, and 4 hours after issuance to be exact. (4 hours is an example, there will be a field for the form-filler person to set the hours).

Hopefully this concept is not too complicated to understand, it is a bit complicated to explain.

But do you see what I mean? And if so, could you help me do this? The DB may come in handy, but I don't know how to set that up, I will need some help.

Anyone!? As you see I am a wreck in the birth of this project which would be great to have running!!

Please respond ASAP, I REALLY appreciate it!! And Turbo, thanks for responding, anymore info?
  #4  
Old 06-Aug-2006, 22:05
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: HTML Form to PHP File - Help Requested


Quote:
Originally Posted by vigilantweather
Thanks for the link ... I already have MySQL and PHP installed.
I understand, that's why I suggested to start at Lesson 2, I just gave you the link from the beginning. [Lesson 2 gets into the form stuff you were asking about]

For the database part, since you were not sure about using one, I noticed that you claimed:
Quote:
Originally Posted by vigilantweather
I am thinking about saving the results for a specificed time period and showing everyone the results for that time period.
How do you plan to save/store the results [and recall them later]? The results *could* be stored in a small database specific for that purpose.

It all depends on the overall goal/plan.

Let's see if other posters have other ideas to offer.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #5  
Old 06-Aug-2006, 22:12
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: HTML Form to PHP File - Help Requested


There are basically only 2 ways for you to save the data supplied by a user. Inside a text file or inside a database table.

You have to decide which before you seek assistance here.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #6  
Old 06-Aug-2006, 22:17
vigilantweather vigilantweather is offline
New Member
 
Join Date: Feb 2006
Posts: 28
vigilantweather is on a distinguished road
Exclamation

Re: HTML Form to PHP File - Help Requested


Ok thanks, I appreciate all the help...

Quote:
How do you plan to save/store the results [and recall them later]? The results *could* be stored in a small database specific for that purpose.

This is one of the parts that I am left in the dark at. How do I automatically and instantly store this information in a database? And how do I recall them later?

I suppose I could use MySQL for the database, and PHP for recalling.

I understand how I want this all set-up, and I understand how the final product will work (granted all goes well).


Quote:
You have to decide which before you seek assistance here.

And admin-- I choose database to be safe since there are going to be multiple fields and it seems safer and more interactive with PHP.

I am just a little in the dark about posting the data to the database and calling it back. I know what I want to do, I (think) I know how this will be done, as you both mentioned--database, so MySQL. So how do I get it in the database and called back into PHP for everyone to see--details on my first and my second post in this thread, please see them to see what I mean.

Thanks guys, I really appreciate the help!
  #7  
Old 07-Aug-2006, 10:35
vigilantweather vigilantweather is offline
New Member
 
Join Date: Feb 2006
Posts: 28
vigilantweather is on a distinguished road
Exclamation

Re: HTML Form to PHP File - Help Requested


Alright... the database is running, my setup is correct, and I am one step closer to my (hopefully) final product. I have a file called submit.php submitting data to my MySQL database. And a file called view.php recalling the data and showing it.

I will post the code to show you.

submit.php
PHP Code:

<?
include("db.php");

$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
$field3 = $_POST['field3'];
if($_POST['sub'] == "yes") {
if($field1 == "") { $error .= "You did not put any information for field1<BR>"; } //checks to see if the user filled in field1, or if they put in too much information, and defines the variable error if they did
if(strlen($field1) > 30) { $error .= "Field1 is too long.<BR>"; }

if($field2 == "") { $error .= "You did not put any information for field2<BR>"; } //checks to see if the user filled in field1, or if they put in too much information, and defines the variable error if they did
if(strlen($field2) > 256) { $error .= "Field2 is too long.<BR>"; }

if($field3 == "") { $error .= "You did not put any information for field3<BR>"; } //checks to see if the user filled in field1, or if they put in too much information, and defines the variable error if they did
if(strlen($field3) > 256) { $error .= "Field3 is too long<BR>."; }
}
if($_GET['success'] != "yes") { ?>
<form action="submit.php" method=POST>
Field1: <input type="text" maxlength="30" name="field1" <? if(isset($field1)) { echo "value=\"" . $field1 . "\""; } ?>><BR>
Field2: <input type="text" maxlength="256" name="field2" <? if(isset($field2)) { echo "value=\"" . $field2 . "\""; } ?>><BR>
Field3: <input type="text" maxlength="256" name="field3" <? if(isset($field3)) { echo "value=\"" . $field3 . "\""; } ?>><BR>
<input type="hidden" name="sub" value="yes">
<input type="submit" value="Submit!">
</form>
<?
}
/* 
note: .= defines a variable or adds onto it if it already exists... for example
$var1 = "hello";
$var1 .= " my name is corbin";
echo $var1;
would out put hello my name is corbin
*/
if(isset($error)) {
echo "There was one or more error!<BR>";
echo $error;
}
else {
if(($_GET['success'] != "yes") && ($_POST['sub'] == "yes")) { // checks to see if $error is set of if the GET variable of success does not equal yes
$field1 = htmlspecialchars($field1);// if $field does not return an error it replaces any thing that could be interpetted as a browser as html
$field2 = htmlspecialchars($field2);
$field3 = htmlspecialchars($field3);
$q = mysql_query("INSERT INTO `" . $table_name . "` (`field1` , `field2` , `field3`) VALUES ('" . $field1 . "', '" . $field2 . "', '" . $field3 ."')");
if($q) { //what to do if the mysql query is successful 
$error = NULL;
?>
<meta http-equiv="refresh" content="0;url=<? echo $_SERVER['HTTP_SELF'] . "?success=yes"; ?>" ?>">
<?
//by forwarding to its self the page will clear its post values so if a user hits refresh its not inserted into the database again...
}  //the meta tag has it forward it to this page cept with the $_GET['success'] tag set
}
elseif($_GET['success'] == "yes") { //what to do if $_GET['success'] does equal yes
echo "Information successfully put in the database!<BR> View it <a href=\"view.php\">Here</a>.";
}
}
mysql_close(); //closes the link to mysql}
?>


view.php
PHP Code:

<?
include("db.php");
$q = mysql_query("SELECT * from `" . $table_name . "`");
while($row = mysql_fetch_assoc($q)) {
echo "Field1: " . $row['field1'] . ", Field2: " . $row['field2'] . ", Field3: " . $row['field3'] . "<BR>";
}
if(mysql_num_rows($q) < 1) { echo "No data has been put into the database yet"; }

mysql_close(); //closes the link to mysql
?>


My issues now are:

Editing the form to suit my needs (and not screwing up the file!!), and hopefully making view.php display the data neatly and how I want it.

First off,
Can I edit the form without screwing up the data (seems like a lot of code editing would be needed)

Secondly,
Can I make view.php look a little something like this (custom text at top with date & time form was submitted)

VWFN - BOS
Short Term Outlook
*DATE FORM SUBMITTED* - *TIME FORM SUBMITTED*

---ONE OF THE FORM FIELDS HERE (it would be a textarea to display the weather alert---

---ANOTHER FIELD (forecaster's [form fillers] last name; entered in form text box field---

***** This should be easy, and I have seen it done before, so hopefully I, too can pull it off!!

But back to what I was saying earlier. Another field is the form filler/forecaster-specified alert expiration. I would like for the person filling the form to say that the alert with expire in 6 hours, or 3 hours, or whatever he/she enters. And then that automatically erases the data from the database, so view.php will not show it after the specified amount of hours.

Once again, this has been done before, I just don't know how exactly to write the code to suit my needs, or what needs to be done. Any help is appreciated, thanks!!
  #8  
Old 07-Aug-2006, 11:50
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: HTML Form to PHP File - Help Requested


For the first part, not really sure what you mean there, but the form should be editable without messing with data.

On the second part, Lesson 3 of the link (from a prior post) shows how to create a title that can be 'included' across as many php files as needed. Something like this can be done to have a custom header/layout -- even if relative to only one file.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #9  
Old 07-Aug-2006, 11:51
vigilantweather vigilantweather is offline
New Member
 
Join Date: Feb 2006
Posts: 28
vigilantweather is on a distinguished road

Re: HTML Form to PHP File - Help Requested


Ok thanks, I will check it out... thanks for the link by the way!
  #10  
Old 07-Aug-2006, 13:08
vigilantweather vigilantweather is offline
New Member
 
Join Date: Feb 2006
Posts: 28
vigilantweather is on a distinguished road

Re: HTML Form to PHP File - Help Requested


For anyone here--

Please see my code for submit.php (post #7 in this thread).

How do I change the form to allow radio options (those dot options to select) in the form for a field and enter that in the database. I also need a textarea field, not a text box, but a large, textarea one.

I tried simply replacing the html type code "<input name", etc. or something like that with the textarea one and radio one to suit my needs... I saved and replaced the file on my server and still they were text boxes!! How do I get the form to allow me to do such a thing?

Do you have any code to replace it?

Thanks in advance!!
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
Upload Script da_bomb50 MySQL / PHP Forum 6 21-Mar-2005 12:01
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28
loading an html file from a db using php mdonovan Web Design Forum 8 22-Mar-2004 00:38

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:47.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.