Hi,
I'm playing with a tutorial on writing to a text file, and the sample in my book worked fine, but when I tried my own script by taking data from a simple form and trying to write a variable and its value to a file, it keeps trying to download instead of executing the script. What might be causing this? I have 3 files: a form, a php file that does the processing, and a text file (called week1.txt) that holds the information that I'm trying to add.
Here's my form. The value entered will be either "open" or "closed":
<html>
<head>
<title>Write to Week 1</title>
</head>
<body>
<form name="form1" action="writetoweek1.php" method="post">
Friday 2-3 p.m.: <input name="friday2to3status"><br>
<input type="submit">
</form>
</body>
</html>
Here's what I have for the processing script called "writetoweek1.php":
<?
$friday2to3status = $_POST['friday2to3status'];
$filename = "/WINDOWS/Desktop/Testing/week1.txt";
$newstring = "\$friday2to3='" + $friday2to3status + "'";
$myfile = @fopen($filename, "a" or die("Couldn't open file."
@fwrite($myfile, $newstring) or die("Couldn't write to file."
$msg = "<p>$newstring has been added to file</p>";
fclose($myfile);
?>
<html>
<head>
<title>Adding Variables and Their Values to a Text File</title>
</head>
<body>
<?
echo "$msg";
?>
</body>
</html>
Can anyone see the problem? Thanks for any tips.
I'm playing with a tutorial on writing to a text file, and the sample in my book worked fine, but when I tried my own script by taking data from a simple form and trying to write a variable and its value to a file, it keeps trying to download instead of executing the script. What might be causing this? I have 3 files: a form, a php file that does the processing, and a text file (called week1.txt) that holds the information that I'm trying to add.
Here's my form. The value entered will be either "open" or "closed":
<html>
<head>
<title>Write to Week 1</title>
</head>
<body>
<form name="form1" action="writetoweek1.php" method="post">
Friday 2-3 p.m.: <input name="friday2to3status"><br>
<input type="submit">
</form>
</body>
</html>
Here's what I have for the processing script called "writetoweek1.php":
<?
$friday2to3status = $_POST['friday2to3status'];
$filename = "/WINDOWS/Desktop/Testing/week1.txt";
$newstring = "\$friday2to3='" + $friday2to3status + "'";
$myfile = @fopen($filename, "a" or die("Couldn't open file."
@fwrite($myfile, $newstring) or die("Couldn't write to file."
$msg = "<p>$newstring has been added to file</p>";
fclose($myfile);
?>
<html>
<head>
<title>Adding Variables and Their Values to a Text File</title>
</head>
<body>
<?
echo "$msg";
?>
</body>
</html>
Can anyone see the problem? Thanks for any tips.