i have a form that saves to a text file then prints it to another page. the script i use is:
<?
echo "<h2><b><u>Current Hours</u></b></h2>\n";
$data = file('hours.txt');
$data = array_reverse($data);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
echo "Monday:" . $pieces[0] . " - " . $pieces[1] . "<br>Tuesday:" . $pieces[2] . " - " . $pieces[3] . "<br>Wednsday:" . $pieces[4] . " - " . $pieces[5] . "<br>Thursday:" . $pieces[6] . " - " . $pieces[7] . "<br>Friday:" . $pieces[8] . " - " . $pieces[9] . "<br>Saturday:" . $pieces[10] . " - " . $pieces[11] . "<br>Sunday:" . $pieces[12] . " - " . $pieces[13];
}
echo "<hr>\n";
echo "<h2><b><u>Add Hours</u></b></h2>\n";
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'starzec') {
if(!$HTTP_POST_VARS['mon1']) {
echo "You must enter Open time for Monday";
exit;
}
if(!$HTTP_POST_VARS['tues1']) {
echo "You must enter Open time for Tuesday";
exit;
}
if(!$HTTP_POST_VARS['wed1']) {
echo "You must enter Open time for Wednsday";
exit;
}
if(!$HTTP_POST_VARS['thur1']) {
echo "You must enter Open time for Thursday";
exit;
}
if(!$HTTP_POST_VARS['fri1']) {
echo "You must enter Open time for Friday";
exit;
}
if(!$HTTP_POST_VARS['sat1']) {
echo "You must enter Open time for Saturday";
exit;
}
if(!$HTTP_POST_VARS['sun1']) {
echo "You must enter Open time for Sunday";
exit;
}
if(!$HTTP_POST_VARS['mon2']) {
echo "You must enter Close time for Monday";
exit;
}
if(!$HTTP_POST_VARS['tues2']) {
echo "You must enter Close time for Tuesday";
exit;
}
if(!$HTTP_POST_VARS['wed2']) {
echo "You must enter Close time for Wednsday";
exit;
}
if(!$HTTP_POST_VARS['thur2']) {
echo "You must enter Close time for Thursday";
exit;
}
if(!$HTTP_POST_VARS['fri2']) {
echo "You must enter Close time for Friday";
exit;
}
if(!$HTTP_POST_VARS['sat2']) {
echo "You must enter Close time for Saturday";
exit;
}
if(!$HTTP_POST_VARS['sun2']) {
echo "You must enter Close time for Sunday";
exit;
}
if(strstr($HTTP_POST_VARS['mon1'],"|")) {
echo "Monday Open cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['mon2'],"|")) {
echo "Monday Close cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['tues1'],"|")) {
echo "Tuesday Open cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['tues2'],"|")) {
echo "Tuesday Close cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['wed1'],"|")) {
echo "Wednsday Open cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['wed2'],"|")) {
echo "Wednsday Close cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['thur1'],"|")) {
echo "Thursday Open cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['thur2'],"|")) {
echo "Thursday Close cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['fri1'],"|")) {
echo "Friday Open cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['fri2'],"|")) {
echo "Friday Close cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['sat1'],"|")) {
echo "Saturday Open cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['sat2'],"|")) {
echo "Saturday Close cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['sun1'],"|")) {
echo "Sunday Open cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['sun2'],"|")) {
echo "Sunday Close cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('hours.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line .= "|" . $HTTP_POST_VARS['mon1'];
$line .= "|" . $HTTP_POST_VARS['mon2'];
$line .= "|" . $HTTP_POST_VARS['tues1'];
$line .= "|" . $HTTP_POST_VARS['tues2'];
$line .= "|" . $HTTP_POST_VARS['wed1'];
$line .= "|" . $HTTP_POST_VARS['wed2'];
$line .= "|" . $HTTP_POST_VARS['thur1'];
$line .= "|" . $HTTP_POST_VARS['thur2'];
$line .= "|" . $HTTP_POST_VARS['fri1'];
$line .= "|" . $HTTP_POST_VARS['fri2'];
$line .= "|" . $HTTP_POST_VARS['sat1'];
$line .= "|" . $HTTP_POST_VARS['sat2'];
$line .= "|" . $HTTP_POST_VARS['sun1'];
$line .= "|" . $HTTP_POST_VARS['sun2'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
echo "<b>Hours Edited</b>\n";
} else {
echo "Bad Password";
}
}
?>
but my problem is when it prints it, it prints like this:
Monday:7 - 7
Tuesday: -
Wednsday: -
Thursday: -
Friday: -
Saturday: -
Sunday: - Monday:6 - 6
Tuesday: -
Wednsday: -
Thursday: -
Friday: -
Saturday: -
Sunday: - Monday:5 - 5
Tuesday: -
Wednsday: -
Thursday: -
Friday: -
Saturday: -
Sunday: - Monday:4 - 4
Tuesday: -
Wednsday: -
Thursday: -
Friday: -
Saturday: -
Sunday: - Monday:3 - 3
Tuesday: -
Wednsday: -
Thursday: -
Friday: -
Saturday: -
Sunday: - Monday:2 - 2
Tuesday: -
Wednsday: -
Thursday: -
Friday: -
Saturday: -
Sunday: - Monday:1 - 1
Tuesday: -
Wednsday: -
Thursday: -
Friday: -
Saturday: -
Sunday: -
can someone help me?