Jump to content


Photo

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


  • Please log in to reply
3 replies to this topic

#1 buildakicker

buildakicker
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 19 October 2006 - 09:35 PM

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.

<!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>

Thanks!

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 19 October 2006 - 10:10 PM

Turn error reporting on at the top of your script...

error_reporting(E_ALL);

You should be generating quite a few.

#3 buildakicker

buildakicker
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 19 October 2006 - 10:30 PM

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...

#4 buildakicker

buildakicker
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 20 October 2006 - 12:06 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users