Jump to content

Recommended Posts

I'm pretty new at php but please give me as much feedback as possible.

 

What I'm trying to create: as part of a learning experience, I'm trying to create a page(text.html) with a form that you can type in a string and then press submit. This submit button uses text2.php to take the string and change testing.txt to whatever the string was. Then i want it to print out whatever testing.txt IS (after it was changed by the form)

 

Heres what i have,

 

text.html


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="text2.php" method="post"> 
<label for="words">words:</label> <input name="words" type="text" /> 
<input type="submit" value="submit" name="submit"/>
</body>
</html>

text2.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php
$myFile = "testing.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $_GET["words"];
fwrite($fh, $stringData);
fclose($fh);
myFile = "testing.txt";
$fh = fopen($myFile, 'r') or die("can't open file");
$theData = fread($fh, filesize($myFile));
echo $theData;
fclose($fh);
?>
</body>
</html>

 

 

 

 

 

 

Can someone please help me understand what I'm doing :).

Link to comment
https://forums.phpfreaks.com/topic/56673-solved-help-with-file-editing/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.