Jump to content

[SOLVED] Logs


TFD3

Recommended Posts

Quick question here....

 

Open this page: http://www.alabamaweather.org/beta/dispatch/test.php

DONT type anything in the fields and just hit the refresh button a few times. You will see |||||| printed each time you hit refresh or load the URL. How can I get it to NOT do that? The script im using is below:

<html>
<head><title>911 Dispatch Logs</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs </H1>
<?php
// This is a form with "sticky" fields .....

?>


<form method=post>
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Department:</TD>
<TD><select name=one>
  <?php
  $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ;
  foreach ($compass as $possibility) {
     echo ("<option");
     if ($HTTP_POST_VARS["one"] == $possibility) echo (" selected");
     echo (">$possibility");
  }
  ?></select></TD>
</TR>
<TR>
<TD>Received:</TD>
<TD><input name=two size=60 maxlength=100
  value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["two"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input name=three size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["three"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input name=four size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["four"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input name=five size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["five"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input name=six size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["six"])));
  ?>" size=15></TD>
</TR>
</TABLE>
</select>
<input type="Submit" value="Submit">
<input type="Reset" value="Clear">
</form>

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

$fh = fopen("../data","a");
fputs($fh,
  $HTTP_POST_VARS["one"]." | ".
  $HTTP_POST_VARS["two"]." | ".
  $HTTP_POST_VARS["three"]." | ".
  $HTTP_POST_VARS["four"]." | ".
  $HTTP_POST_VARS["five"]." | ".
  $HTTP_POST_VARS["six"]." | ".
  "\n");
fclose($fh);

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

<FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b>
<?php
$stuff = implode("",file("../data"));
echo (nl2br(htmlspecialchars(stripslashes($stuff))));
?></b>
</FONT>


</body>
</html>

 

I think it needs just an if or elseif statement(s) but I dont know where to place it at.

Any help is greatly appreciated :)

 

Thanks,

Kenny

 

Link to comment
https://forums.phpfreaks.com/topic/62083-solved-logs/
Share on other sites

Well, you only want to be doing this part of your code:

 

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

$fh = fopen("../data","a");
fputs($fh,
  $HTTP_POST_VARS["one"]." | ".
  $HTTP_POST_VARS["two"]." | ".
  $HTTP_POST_VARS["three"]." | ".
  $HTTP_POST_VARS["four"]." | ".
  $HTTP_POST_VARS["five"]." | ".
  $HTTP_POST_VARS["six"]." | ".
  "\n");
fclose($fh);

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

If the submit button has been clicked. Try:

<html>
<head><title>911 Dispatch Logs</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs </H1>
<?php
// This is a form with "sticky" fields .....

?>


<form method=post>
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Department:</TD>
<TD><select name=one>
  <?php
  $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ;
  foreach ($compass as $possibility) {
     echo ("<option");
     if ($HTTP_POST_VARS["one"] == $possibility) echo (" selected");
     echo (">$possibility");
  }
  ?></select></TD>
</TR>
<TR>
<TD>Received:</TD>
<TD><input name=two size=60 maxlength=100
  value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["two"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input name=three size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["three"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input name=four size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["four"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input name=five size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["five"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input name=six size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["six"])));
  ?>" size=15></TD>
</TR>
</TABLE>
</select>
<input type="Submit" value="Submit" name="submit">
<input type="Reset" value="Clear">
</form>

<?php
// Save all the fields on any previous form to a file
if(isset($HTTP_POST_VARS['submit'])){
    $fh = fopen("../data","a");
    fputs($fh,
    $HTTP_POST_VARS["one"]." | ".
    $HTTP_POST_VARS["two"]." | ".
    $HTTP_POST_VARS["three"]." | ".
    $HTTP_POST_VARS["four"]." | ".
    $HTTP_POST_VARS["five"]." | ".
    $HTTP_POST_VARS["six"]." | ".
    "\n");
fclose($fh);
}
// Echo the file contents onto the end of the form
?>

<FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b>
<?php
$stuff = implode("",file("../data"));
echo (nl2br(htmlspecialchars(stripslashes($stuff))));
?></b>
</FONT>


</body>
</html>

 

Note the fact that i added a name to your submit button. You'll need that for php to check if it the form has been submitted. If you're running a version of php greater than 4.1, consider changing $HTTP_POST_VARS to $_POST. Thats the new version.

Link to comment
https://forums.phpfreaks.com/topic/62083-solved-logs/#findComment-309098
Share on other sites

Is there a reason why your using a flat file instead of a database? I am assuming you want something like this...

 

<html>
<head><title>911 Dispatch Logs</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs </H1>
<?php
// This is a form with "sticky" fields .....

?>


<form method=post>
<input type="hidden" name="posted" value="true">
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Department:</TD>
<TD><select name=one>
 <?php
 $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ;
 foreach ($compass as $possibility) {
    echo ("<option");
    if ($HTTP_POST_VARS["one"] == $possibility) echo (" selected");
    echo (">$possibility");
 }
 ?></select></TD>
</TR>
<TR>
<TD>Received:</TD>
<TD><input name=two size=60 maxlength=100
 value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php
 echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["two"])));
 ?>" size=15></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input name=three size=60 maxlength=100
 value="<?php
 echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["three"])));
 ?>" size=15></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input name=four size=60 maxlength=100
 value="<?php
 echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["four"])));
 ?>" size=15></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input name=five size=60 maxlength=100
 value="<?php
 echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["five"])));
 ?>" size=15></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input name=six size=60 maxlength=100
 value="<?php
 echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["six"])));
 ?>" size=15></TD>
</TR>
</TABLE>
</select>
<input type="Submit" value="Submit">
<input type="Reset" value="Clear">
</form>

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

If ($_POST['posted']) {

$fh = fopen("../data","a");
fputs($fh,
 $HTTP_POST_VARS["one"]." | ".
 $HTTP_POST_VARS["two"]." | ".
 $HTTP_POST_VARS["three"]." | ".
 $HTTP_POST_VARS["four"]." | ".
 $HTTP_POST_VARS["five"]." | ".
 $HTTP_POST_VARS["six"]." | ".
 "\n");
fclose($fh);

}

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

<FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b>
<?php
$stuff = implode("",file("../data"));
echo (nl2br(htmlspecialchars(stripslashes($stuff))));
?></b>
</FONT>


</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/62083-solved-logs/#findComment-309101
Share on other sites

Is there a reason why your using a flat file instead of a database? I am assuming you want something like this...

 

<html>
<head><title>911 Dispatch Logs</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs </H1>
<?php
// This is a form with "sticky" fields .....

?>


<form method=post>
<input type="hidden" name="posted" value="true">
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Department:</TD>
<TD><select name=one>
  <?php
  $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ;
  foreach ($compass as $possibility) {
     echo ("<option");
     if ($HTTP_POST_VARS["one"] == $possibility) echo (" selected");
     echo (">$possibility");
  }
  ?></select></TD>
</TR>
<TR>
<TD>Received:</TD>
<TD><input name=two size=60 maxlength=100
  value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["two"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input name=three size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["three"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input name=four size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["four"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input name=five size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["five"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input name=six size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["six"])));
  ?>" size=15></TD>
</TR>
</TABLE>
</select>
<input type="Submit" value="Submit">
<input type="Reset" value="Clear">
</form>

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

If ($_POST['posted']) {

$fh = fopen("../data","a");
fputs($fh,
  $HTTP_POST_VARS["one"]." | ".
  $HTTP_POST_VARS["two"]." | ".
  $HTTP_POST_VARS["three"]." | ".
  $HTTP_POST_VARS["four"]." | ".
  $HTTP_POST_VARS["five"]." | ".
  $HTTP_POST_VARS["six"]." | ".
  "\n");
fclose($fh);

}

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

<FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b>
<?php
$stuff = implode("",file("../data"));
echo (nl2br(htmlspecialchars(stripslashes($stuff))));
?></b>
</FONT>


</body>
</html>

 

YES! Thats what I need however I found this error:

 

When I go to change

 

$fh = fopen("../data","a");
and
$stuff = implode("",file("../data"));

TO

$fh = fopen("../data1","a");
and
$stuff = implode("",file("../data1"));

just changed the data to data1 so I can get a fresh blank page.

 

I get this error:

 

Warning: file(../data1) [function.file]: failed to open stream: No such file or directory in /home/alabamaw/public_html/beta/dispatch/test.php on line 90

Warning: implode() [function.implode]: Bad arguments. in /home/alabamaw/public_html/beta/dispatch/test.php on line 90

 

I used to be able to change those two lines and it worked, but now it does not. However this is what I need, now just to erase everything so I can start using it.

 

 

Link to comment
https://forums.phpfreaks.com/topic/62083-solved-logs/#findComment-309114
Share on other sites

Ok, can you post up the code you are using now, just so we can see exactly where you are at.

 

As far as the error is concerned, its basically saying the file doesn't exist. Im a little confused as to what file you're trying to access anyway. Is it a text file? Shouldn't there be an extension for the file?

Link to comment
https://forums.phpfreaks.com/topic/62083-solved-logs/#findComment-309162
Share on other sites

This is the script:

<html>
<head><title>911 Dispatch Logs</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs </H1>
<?php
// This is a form with "sticky" fields .....

?>


<form method=post>
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Department:</TD>
<TD><select name=one>
  <?php
  $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ;
  foreach ($compass as $possibility) {
     echo ("<option");
     if ($HTTP_POST["one"] == $possibility) echo (" selected");
     echo (">$possibility");
  }
  ?></select></TD>
</TR>
<TR>
<TD>Received:</TD>
<TD><input name=two size=60 maxlength=100
  value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST["two"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input name=three size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST["three"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input name=four size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST["four"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input name=five size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST["five"])));
  ?>" size=15></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input name=six size=60 maxlength=100
  value="<?php
  echo (htmlspecialchars(stripslashes($HTTP_POST["six"])));
  ?>" size=15></TD>
</TR>
</TABLE>
</select>
<input type="Submit" value="Submit" name="Submit">
<input type="Reset" value="Clear" name="Clear">
</form>

<?php
// Save all the fields on any previous form to a file
if(isset($HTTP_POST['submit'])){
    $fh = fopen("../data","a");
    fputs($fh,
    $HTTP_POST["one"]." | ".
    $HTTP_POST["two"]." | ".
    $HTTP_POST["three"]." | ".
    $HTTP_POST["four"]." | ".
    $HTTP_POST["five"]." | ".
    $HTTP_POST["six"]." | ".
    "\n");
fclose($fh);
}
?>

<FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b>
<?php
// Echo the file contents onto the end of the form
$stuff = implode("",file("../data"));
echo (nl2br(htmlspecialchars(stripslashes($stuff))));
?></b>
</FONT>

</body>
</html>

 

The error is gone now b/c I fixed that my self using trial and error.

Open this page: http://www.alabamaweather.org/beta/dispatch/test.php

Type something in each field, click submit. The data now does not show up like before.

 

Link to comment
https://forums.phpfreaks.com/topic/62083-solved-logs/#findComment-309166
Share on other sites

Ah, i didn't mean use $HTTP_POST. Its just $_POST. Try:

 

<html>
<head><title>911 Dispatch Logs</title></head>
<body bgcolor="#002233" text=white>
<H1>911 Dispatch Logs </H1>
<?php
// This is a form with "sticky" fields .....

?>


<form method=post>
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="50%">
<TR>
<TD>Department:</TD>
<TD><select name=one>
 <?php
 $compass = array ("Center Point","Birmingham","Trussville","Fultondale") ;
 foreach ($compass as $possibility) {
    echo ("<option");
    if ($_POST["one"] == $possibility) echo (" selected");
    echo (">$possibility");
 }
 ?></select></TD>
</TR>
<TR>
<TD>Received:</TD>
<TD><input name=two size=60 maxlength=100
 value="<?php date_default_timezone_set('UTC'); echo date(DATE_RFC822);?>"<?php
 echo (htmlspecialchars(stripslashes($_POST["two"])));
 ?>" size=15></TD>
</TR>
<TR>
<TD>Unit(s):</TD>
<TD><input name=three size=60 maxlength=100
 value="<?php
 echo (htmlspecialchars(stripslashes($_POST["three"])));
 ?>" size=15></TD>
</TR>
<TR>
<TD>Location:</TD>
<TD><input name=four size=60 maxlength=100
 value="<?php
 echo (htmlspecialchars(stripslashes($_POST["four"])));
 ?>" size=15></TD>
</TR>
<TR>
<TD>Type of Call:</TD>
<TD><input name=five size=60 maxlength=100
 value="<?php
 echo (htmlspecialchars(stripslashes($_POST["five"])));
 ?>" size=15></TD>
</TR>
<TR>
<TD>Details:</TD>
<TD><input name=six size=60 maxlength=100
 value="<?php
 echo (htmlspecialchars(stripslashes($_POST["six"])));
 ?>" size=15></TD>
</TR>
</TABLE>
</select>
<input type="Submit" value="Submit" name="Submit">
<input type="Reset" value="Clear" name="Clear">
</form>

<?php
// Save all the fields on any previous form to a file
if(isset($_POST['Submit'])){
   $fh = fopen("../data","a");
   fputs($fh,
   $_POST["one"]." | ".
   $_POST["two"]." | ".
   $_POST["three"]." | ".
   $_POST["four"]." | ".
   $_POST["five"]." | ".
   $_POST["six"]." | ".
   "\n");
fclose($fh);
}
?>

<FONT style="BACKGROUND-COLOR: #808080" COLOR=white><b>
<?php
// Echo the file contents onto the end of the form
$stuff = implode("",file("../data"));
echo (nl2br(htmlspecialchars(stripslashes($stuff))));
?></b>
</FONT>

</body>
</html>

 

Also notice i modified this line:

 

if(isset($_POST['Submit'])){

The keys of arrays are case sensitive, and the name given to the HTML tag was with a capital S, so this needs a capital S too.

Link to comment
https://forums.phpfreaks.com/topic/62083-solved-logs/#findComment-309174
Share on other sites

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.