Jump to content

Archived

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

buildakicker

Submission of Form not working and I am lost as to why...

Recommended Posts

Hello all,

I am glad that there is this community to help me sharpen my php skills.

I have a form that I have created and will be posting data from to a text file. I don't have database access, so no database anything. It's all text files. I am getting better at using them... anyhow.. Here is my code. I can't figure out why it is not posting to the text file.

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FFDB</title>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<body>
<?php
$now = time();
//current date
$date = date("l, d F Y - h:i a",time() - 10800);
//tomorrow
$tomorrow = date("l, d F Y", mktime(0, 0, 0, date("m", $now)  , date("d", $now)+1, date("Y", $now)));

//make sure all data is ready for post
if(isset($_POST['Submit'])){
  $cpal1 = $_POST['cpal1']; 
  $cpal2 = $_POST['cpal2'];
  $cpal3 = $_POST['cpal3'];
  $cpal4 = $_POST['cpal4'];
  $cpal5 = $_POST['cpal5'];
  $csal1 = $_POST['csal1'];
  $csal2 = $_POST['csal2'];
  $csal3 = $_POST['csal3'];
  $csal4 = $_POST['csal4'];
  $csal5 = $_POST['csal5'];
  $ppal1 = $_POST['ppal1']; 
  $ppal2 = $_POST['ppal2'];
  $ppal3 = $_POST['ppal3'];
  $ppal4 = $_POST['ppal4'];
  $ppal5 = $_POST['ppal5'];
  $psal1 = $_POST['psal1'];
  $psal2 = $_POST['psal2'];
  $psal3 = $_POST['psal3'];
  $psal4 = $_POST['psal4'];
  $psal5 = $_POST['psal5'];
 
  $err = '<span class="style1">Please Enter ALL Data</span><br>';
 
  if(empty($csal1)){
      $err;
  }
  if(empty($csal2)){
      $err;
  }
  if(empty($csal3)){
      $err;
  }
  if(empty($csal4)){
      $err;
  }
  if(empty($csal5)){
      $err;
  }
  if(empty($cpal1)){
      $err;
  }
  if(empty($cpal2)){
      $err;
  }
  if(empty($cpal3)){
      $err;
  }
  if(empty($cpal4)){
      $err;
  }
  if(empty($cpal5)){
      $err;
  }
  if(empty($psal1)){
      $err;
  }
  if(empty($psal2)){
      $err;
  }
  if(empty($psal3)){
      $err;
  }
  if(empty($psal4)){
      $err;
  }
  if(empty($psal5)){
      $err;
  }
  if(empty($ppal1)){
      $err;
  }
  if(empty($ppal2)){
      $err;
  }
  if(empty($ppal3)){
      $err;
  }
  if(empty($ppal4)){
      $err;
  }
  if(empty($ppal5)){
      $err;
  }
  //if the form is all good, move on and get the positions in the file to be filled.
  else{
      $filename = 'firedata.txt';
  $filetext = $csal1 . '#' . $csal2 . '#' . $csal3 . '#' . $csal4 . '#' . $csal5 . '#' . $cpal1 . '#' . $cpal2 . '#' . $cpal3 . '#' . $cpal4 . '#' . $cpal5 . '#' . $date . "\n" . $psal1 . '#' . $psal2 . '#' . $psal3 . '#' . $psal4 . '#' . $psal5 . '#' . $ppal1 . '#' . $ppal2 . '#' . $ppal3 . '#' . $ppal4 . '#' . $ppal5 . '#' . $tomorrow . "\n";
     
      // Let's make sure the file exists and is writable first.
      if (is_writable($filename)) {
     
        // that's where $filetext will go when we fwrite() it.
        if (!$handle = fopen($filename, 'w')) {
            echo "Cannot open file ($filename)";
            exit;
        }
     
        // Write $filetext to our opened file.
        if (fwrite($handle, $filetext) === FALSE) {
            echo "Cannot write to file ($filename)";
            exit;
        }
       
        echo "Success, wrote ($filetext) to file ($filename)";
       
        fclose($handle);
     
      } else {
        echo "The file $filename is not writable";
      }
  }
}
?>

<?php
//read the file and store the contents in an array for display in current form
if(file('firedata.txt', 'r')){
list($csal_str, $psal_str) = file('firedata.txt');
$acsal = explode('#', $csal_str);
$apsal = explode('#', $psal_str);
$cdate = array_pop($acsal);
$pdate = array_pop($apsal);

//error testing viewing text file 1st line
print $acsal[0] . ' ' . $acsal[1] . ' ' . $acsal[2] . ' ' . $acsal[3] . ' ' . $acsal[4] . ' ' . $acsal[5] . ' ' . $acsal[6] . ' ' . $acsal[7] . ' ' . $acsal[8] . ' ' . $acsal[9] . ' ' . $cdate;

//error testing viewing text file 2nd line
print $apsal[0] . ' ' . $apsal[1] . ' ' . $apsal[2] . ' ' . $apsal[3] . ' ' . $apsal[4] . ' ' . $apsal[5] . ' ' . $apsal[6] . ' ' . $apsal[7] . ' ' . $apsal[8] . ' ' . $apsal[9] . ' ' . $pdate;

}else {
print "ERROR FILE NOT READABLE";
}
?>

<form action="index.php" method="post" name="form1" id="form1">
  <p>  </p>
  <h4>Actual Activity Levels</h4>
  </p>
  <p>SAL - BOGARD:
    <input name="csal1" type="text" id="csal1" value="<?php echo $acsal[0]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    SAL - CHESTER:
    <input name="csal2" type="text" id="csal2" value="<?php echo $acsal[1]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    SAL - GORDON:
    <input name="csal3" type="text" id="csal3" value="<?php echo $acsal[2]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    SAL - LADDER:
    <input name="csal4" type="text" id="csal4" value="<?php echo $acsal[3]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    SAL - MANZANITA:
    <input name="csal5" type="text" id="csal5" value="<?php echo $acsal[4]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - BOGARD:
    <input name="cpal1" type="text" id="cpal1" value="<?php echo $acsal[5]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - CHESTER:
    <input name="cpal2" type="text" id="cpal2" value="<?php echo $acsal[6]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - GORDON:
    <input name="cpal3" type="text" id="cpal3" value="<?php echo $acsal[7]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - LADDER:
    <input name="cpal4" type="text" id="cpal4" value="<?php echo $acsal[8]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - MANZANITA:
    <input name="cpal5" type="text" id="cpal5" value="<?php echo $acsal[9]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
  </p>
  <p>  </p>
  <h4>Predicted Activity Levels</h4>
  </p>
<p>SAL - BOGARD:
    <input name="csal1" type="text" id="csal1" value="<?php echo $apsal[1]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    SAL - CHESTER:
    <input name="csal2" type="text" id="csal2" value="<?php echo $apsal[2]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    SAL - GORDON:
    <input name="csal3" type="text" id="csal3" value="<?php echo $apsal[3]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    SAL - LADDER:
    <input name="csal4" type="text" id="csal4" value="<?php echo $apsal[4]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    SAL - MANZANITA:
    <input name="csal5" type="text" id="csal5" value="<?php echo $apsal[5]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - BOGARD:
    <input name="cpal1" type="text" id="cpal1" value="<?php echo $apsal[6]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - CHESTER:
    <input name="cpal2" type="text" id="cpal2" value="<?php echo $apsal[7]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - GORDON:
    <input name="cpal3" type="text" id="cpal3" value="<?php echo $apsal[8]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - LADDER:
    <input name="cpal4" type="text" id="cpal4" value="<?php echo $apsal[9]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
    PAL - MANZANITA:
    <input name="cpal5" type="text" id="cpal5" value="<?php echo $apsal[10]; ?>" size="6" style="text-transform: uppercase;" maxlength="6" />
    <br />
</p>
  <p>
    <input type="submit" name="Submit" value="Submit" />
  </p>
</form>
</body>
</html>
[/code]

Thanks!

Share this post


Link to post
Share on other sites
Turn error reporting on at the top of your script...

[code=php:0]
error_reporting(E_ALL);
[/code]

You should be generating quite a few.

Share this post


Link to post
Share on other sites
Hi,

I have never used that function. How do I get it to report the errors? I tried to print, does it just tell me how many?

Thanks...

Share this post


Link to post
Share on other sites
Is this overwriting anything in my txt file?

list($csal_str, $psal_str) = file('firedata.txt');

or is it just parsing two vars out of it?

thanks!

Share this post


Link to post
Share on other sites

×

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.