Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tries to Download File Instead of Executing 1

Status
Not open for further replies.

tnsbuff

Technical User
Jan 23, 2002
216
US
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=&quot;form1&quot; action=&quot;writetoweek1.php&quot; method=&quot;post&quot;>
Friday 2-3 p.m.: <input name=&quot;friday2to3status&quot;><br>
<input type=&quot;submit&quot;>
</form>
</body>
</html>

Here's what I have for the processing script called &quot;writetoweek1.php&quot;:

<?
$friday2to3status = $_POST['friday2to3status'];
$filename = &quot;/WINDOWS/Desktop/Testing/week1.txt&quot;;
$newstring = &quot;\$friday2to3='&quot; + $friday2to3status + &quot;'&quot;;
$myfile = @fopen($filename, &quot;a&quot;) or die(&quot;Couldn't open file.&quot;);
@fwrite($myfile, $newstring) or die(&quot;Couldn't write to file.&quot;);
$msg = &quot;<p>$newstring has been added to file</p>&quot;;
fclose($myfile);
?>
<html>
<head>
<title>Adding Variables and Their Values to a Text File</title>
</head>
<body>
<?
echo &quot;$msg&quot;;
?>
</body>
</html>

Can anyone see the problem? Thanks for any tips.




 
When it is trying to download the file that you are submitting the information too. This means that php is not correctly configured.

What are you running this on?
 
Hi,

I'm running it on Apache under Windows (on my hard drive). I've been doing a series of tutorials, and so far, everything else has worked. It's just when I tried to create this particular script of my own that it started trying to download when submitting the form to the processing script.

Thanks for any suggestions.

 
If Php is properly installed, try re-starting your apache server. This happens to me periodically, and that seems to solve my problem. [cheers]
Cheers!
Laura
 
Thanks Laura,

Restarting the server corrected the problem.
 
One more question:

Can anyone see what's wrong with this line:

$newstring = &quot;\$friday2to3='&quot; + $friday2to3status + &quot;'&quot;;

That's supposed to be the string that's added to the text file, and it should generate:

$friday2to3 = 'open'

since the word &quot;open&quot; was entered in the text box on the submitting form and that field name is called $friday2to3status,

but what's being added is just: 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top