fwrite is refusing to write variables
Posted: Mon Sep 25, 2006 9:57 am
I modified this code from the internet:
Which works dandy. But if I modify it to use my code:
Yet if I hardcode the data to insert () it works fine. But as soon as I use post to get the data from a HTML form it refuses to insert it. But if I echo the variable $write after it has been posted from a HTML form it echos fine.
Regards,
Code: Select all
<?php
$File = "YourFile.txt";
$Handle = fopen($File, 'w');
$Data = "Jane Doe\n";
fwrite($Handle, $Data);
$Data = "Bilbo Jones\n";
fwrite($Handle, $Data);
print "Data Written";
fclose($Handle);
?>Code: Select all
<form method="post"
action="write.php">
<input type="text"
name="edit">
<input type="submit"
value="Write!">
</form>
<?php
$file = "file.txt";
$do = fopen($file, 'w');
$write = $_REQUEST["edit"];
fwrite($do, $write);
echo "<br><br>Inserted $write<br>";
fclose($do);
?>Code: Select all
$write = "teapot";Regards,