Jump to content

[SOLVED] Input Form Question


TFD3

Recommended Posts

I'm trying to set up an input form so when I enter information using the input form the info I type in is sent to another page and placed in a table. That I already have set up but when I hit the refresh button the data in the table is erased.

 

Here is the links for adding data to the table:

http://beta.alabamaweather.org/dispatch/dispatch.php

After you type in information in the blanks and click the Submit button you get sent to this page along with the data that you typed in:

http://beta.alabamaweather.org/dispatch/index.php

 

Here is the input form im using:

<html>
<body>
<title>Dispatch</title>

<b>  <?php date_default_timezone_set('UTC');
echo date(DATE_RFC822);?></b>
<form action="index.php" method="post">
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Received:</TD>
<TD><input type="text" name="received" size=60 maxlength=100/></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input type="text" name="calltype" size=60 maxlength=100/></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input type="text" name="location" size=60 maxlength=100/></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input type="text" name="unit" size=60 maxlength=100/></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input type="text" name="details" size=60 maxlength=150/></TD>
</TR>
</TABLE>
<input type=submit value="Submit Incident"><input type=reset value="Reset Form">
</form>

</body>
</html

 

On the output page which is http://beta.alabamaweather.org/dispatch/index.php

<?php echo $_POST["received"]; ?>
<?php echo $_POST["calltype"]; ?>
<?php echo $_POST["location"]; ?>
<?php echo $_POST["units"]; ?>
<?php echo $_POST["details"]; ?>

 

 

My question is...How do I keep the data that I type in placed in the table without having it erased when I hit the refresh button?

 

Link to comment
https://forums.phpfreaks.com/topic/62057-solved-input-form-question/
Share on other sites

You get a mysql database and save it in there ;). OR learn file IO and you can save it in there, much harder in my opion.

 

You can also learn to save it to a txt file if you do not wish to use mysql database's yet.

(Or if its not a permanent "viewable" text, just use cookies)

 

text files are highly unsafe and can be downloaded by anyone once its found... Go for mysql it's very simple.

I have done some searching and have found this script that is the "idea" of what I need.

However when u run the script there is only one input field and I need to add another.

Can someone show me what to add to make another input field?

Here is the script on the server:

http://www.alabamaweather.org/beta/dispatch/call1.php

 

And here is the script its self:

<html>
<head><title>Form Elements to file</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs</h1>
<?php

// This is a form with "sticky" fields .....

?>
<form method=post>
Text Box <input name=one
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["one"])));
  ?>" size=15><br>
Checkbox <input name=two type=checkbox
  <?php
  if ($HTTP_POST_VARS["two"] != "") echo ("checked");
  ?>><br>
Select <select name=three>
  <?php
  $compass = array ("North","South","East","West") ;
  foreach ($compass as $possibility) {
     echo ("<option");
     if ($HTTP_POST_VARS["three"] == $possibility) echo (" selected");
     echo (">$possibility");
  }
  ?></select><br>
<input type=submit>
</form>
<?php

// Save all the fields on any previous form to a file

$fh = fopen("../testdata","a");
fputs($fh,$HTTP_POST_VARS["one"]." - ".
  $HTTP_POST_VARS["two"]." - ".
  $HTTP_POST_VARS["three"]." - ".time().
  "\n");
fclose($fh);

// Echo the file contents onto the end of the form

$stuff = implode("",file("../testdata"));
echo (nl2br(htmlspecialchars(stripslashes($stuff))));

?>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.