I read many of the other questions on this site revolving around this error, none of which were able to help me, The below php code takes the data input from the html file and sends it to the php file, after printing "Hello Name" on the page, it should open a file called My_file.txt, which is already created, and write to it, I have been unable to do so, any help would be great, here is my code:
index.html file:
<html>
<head><title>Hello Friend</title></head>
<body bgcolor="black">
<p style="text-align:center">
<font color="white">
<form action="data.php" method="post">
<input type="text" name="myname" id="myname">
<input type="submit" value="Submit">
</form>
</body>
</html>
data.php file:
<html>
<head>
<title>Hello Friend, this is php</title>
</head>
<body bgcolor="black">
<font color="white">
<code>
<?php
$name = $_POST["myname"];
echo "Hello, " . $name;
$filename = "My_file.txt";
chmod($filename, 777);
$f = fopen($filename, "w") or die("Unable to open file");
fwrite($f, "The Name is: " . $name);
f.close($f);
echo fgets($f);
fclose($f);
?>
Output:
Hello, JohnUnable to open file