whenever i try to create a new txtfile using create button although the file get create but the data is not written into the file. i just het a blank file. what is the error ?

```
    <?php
    error_reporting(0);
    if(isset($_POST['sub']))
    {
        $fname=$_POST["txtfile"];
        $cont=$_POST['txtarea'];
        if($_POST['sub']=="create")
        {
            fopen($fname,"w");
            fwrite($fname, $cont);
        }
        else if($_POST['sub']=="read")
        {
            echo file_get_contents($fname); 
        }

        else if($_POST['sub']=="delete")
        {
            unlink($fname);
        }

        else if($_POST['sub']=="append")
        {
            $cont=$_POST['txtarea'];
            $fp=fopen($fname,"a");
            fwrite($fp,$cont);
        }
    }
    ?>

```

here is the html code of above program. should i insert the php code for reading the file into the textarea code in html.?

```
<!DOCTYPE html>
<html>
<h3>file handling concept</h3>
<style type="text/css">

#form{
    height: 200px;
    width: 400px;
    margin: 10px;
}
label {
    float: left;
    margin-right: 10px;
    width: 70px;
    padding-top: 5px;
    font-size: 15px;
}
#form input, #form textarea{
    padding: 5px;
    width: 306px;
    font-family: Helvetica, sans-serif;
    font-size: 15px;
    margin: 0px 0px 0px 0px;
    border: 2px solid #ccc;
}
#button input{
    float: right;
    margin: 5px;
    width: 60px;
    padding: 5px;
    border: 1px solid #ccc;
}   
</style>
<div id="form">
    <form method="POST" action="filehandling.php">

        <label for="name">Filename:</label>
        <input type="text" name="txtfile" placeholder="file-name.txt" />

        <label for="name">content:</label>
        <textarea name="txtarea" placeholder="write some content">

</textarea>
        <div id="button">
            <input type='submit' name='sub' value='create'>
            <input type='submit' name='sub' value='delete'>
            <input type='submit' name='sub' value='append'>
            <input type='submit' name='sub' value='read'>
        </div>
    </form>
</div>
</html>

```