Hi,
Am I trying to be too clever here?
I am trying to write a PHP page to enable me to enter values into a form
then write those values to a text file.
I want to use the form & table that displays these fileds and values in
different ways so am creating one page and parsing variables to it.
The problem appears to be in trying to write the values to a text file. The
page displays the field names correctly but when I submit the form and try
to write the values to a text file, separated by # what I get is
############## but no values !!!
Any help greatly appreciated .... Paul.
Config.php:
$filename = "./config.txt"
$fieldnames = array ("business_name ", "business_addre ss", "business_phone ");
// There are more but you get the idea
// Firstly if the file exists read the existing values and store them in an
array where $fieldname[$i] = $data[$i]
if(file_exists( $filename))
{
$fp = fopen($filename , "r");
$contents = fread($fp, filesize($filen ame));
$data = explode("#", $contents, 16);
for($i = 0; $i < 17; ++$i)
{
$fieldnames[$i] = $data[$i];
}
fclose($fp);
// Display the form in update mode with current values as defaults
$button = "update";
include("./config_table.ph p");
}
elseif($submit == "save" || $submit == "update")
{
// The form has been submitted so write the values to the text file
$fp = fopen($filename , "w+");
for($i = 0; $i < 17; ++$i)
{
fwrite($fp, $data[$i] . "#"); // uses the # symbol to separate data
items
}
fclose($fp);
print '<SPAN CLASS="message" >Your configuration values have been ' .
$submit . 'd successfully.</SPAN>';
}
else
{
// Display the form in install mode as this if the first time the file
has been run
$button = "save";
include("./config_table.ph p");
}
Config_table.ph p:
<FORM NAME="configura tion" METHOD="post" ACTION="config. php">
<TABLE>
<?php $f = 0; ?>
<TR><TD>Busines s Name</TD>
<TD><INPUT TYPE="text" MAXLENGTH="255" SIZE="40" NAME="<?php echo
$fieldnames[$f]; ?>" VALUE="<?php echo $fieldnames[$f]; ?>"></TD></TR>
<?php ++$f; ?>
<TR><TD>Busines s Address</TD>
<TD><INPUT TYPE="text" MAXLENGTH="255" SIZE="40" NAME="<?php echo
$fieldnames[$f]; ?>" VALUE="<?php echo $fieldnames[$f]; ?>"></TD></TR>
<?php ++$f; ?>
<TR><TD>Busines s Phone</TD>
<TD><INPUT TYPE="text" MAXLENGTH="255" SIZE="40" NAME="<?php echo
$fieldnames[$f]; ?>" VALUE="<?php echo $fieldnames[$f]; ?>"></TD></TR>
<TR><TH COLSPAN="2"><IN PUT TYPE="submit" VALUE="<?php echo $button;
?>"> <INPU T TYPE="reset" VALUE="reset"></TH></TR></TABLE></FORM>
Am I trying to be too clever here?
I am trying to write a PHP page to enable me to enter values into a form
then write those values to a text file.
I want to use the form & table that displays these fileds and values in
different ways so am creating one page and parsing variables to it.
The problem appears to be in trying to write the values to a text file. The
page displays the field names correctly but when I submit the form and try
to write the values to a text file, separated by # what I get is
############## but no values !!!
Any help greatly appreciated .... Paul.
Config.php:
$filename = "./config.txt"
$fieldnames = array ("business_name ", "business_addre ss", "business_phone ");
// There are more but you get the idea
// Firstly if the file exists read the existing values and store them in an
array where $fieldname[$i] = $data[$i]
if(file_exists( $filename))
{
$fp = fopen($filename , "r");
$contents = fread($fp, filesize($filen ame));
$data = explode("#", $contents, 16);
for($i = 0; $i < 17; ++$i)
{
$fieldnames[$i] = $data[$i];
}
fclose($fp);
// Display the form in update mode with current values as defaults
$button = "update";
include("./config_table.ph p");
}
elseif($submit == "save" || $submit == "update")
{
// The form has been submitted so write the values to the text file
$fp = fopen($filename , "w+");
for($i = 0; $i < 17; ++$i)
{
fwrite($fp, $data[$i] . "#"); // uses the # symbol to separate data
items
}
fclose($fp);
print '<SPAN CLASS="message" >Your configuration values have been ' .
$submit . 'd successfully.</SPAN>';
}
else
{
// Display the form in install mode as this if the first time the file
has been run
$button = "save";
include("./config_table.ph p");
}
Config_table.ph p:
<FORM NAME="configura tion" METHOD="post" ACTION="config. php">
<TABLE>
<?php $f = 0; ?>
<TR><TD>Busines s Name</TD>
<TD><INPUT TYPE="text" MAXLENGTH="255" SIZE="40" NAME="<?php echo
$fieldnames[$f]; ?>" VALUE="<?php echo $fieldnames[$f]; ?>"></TD></TR>
<?php ++$f; ?>
<TR><TD>Busines s Address</TD>
<TD><INPUT TYPE="text" MAXLENGTH="255" SIZE="40" NAME="<?php echo
$fieldnames[$f]; ?>" VALUE="<?php echo $fieldnames[$f]; ?>"></TD></TR>
<?php ++$f; ?>
<TR><TD>Busines s Phone</TD>
<TD><INPUT TYPE="text" MAXLENGTH="255" SIZE="40" NAME="<?php echo
$fieldnames[$f]; ?>" VALUE="<?php echo $fieldnames[$f]; ?>"></TD></TR>
<TR><TH COLSPAN="2"><IN PUT TYPE="submit" VALUE="<?php echo $button;
?>"> <INPU T TYPE="reset" VALUE="reset"></TH></TR></TABLE></FORM>
Comment