Member Avatar for FakeTales

Hey i have three forms on one page , i am getting them to write the data to seperate text files.

If i use on form to post the colour it will write the colour to the text file but if i use the form to select which display i want it will write that to the text file but erase the contents of the colour text file.

<div id="options1" style="height:200px;width:400px;float:left;background:#666;">
            <form
                action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

                <label> Header Text Colour: </label>
                <select name="hdrCol" >
                <option name="hdrCol" value=" Red "> Red </option>
                <option name="hdrCol" value=" Green "> Green </option>
                <option name="hdrCol" value=" Orange "> Orange </option>
                <option name="hdrCol" value=" Yellow "> Yellow </option>
                </select>
                </br>
                </br>
                <input type="submit" name="submitCol" value="Submit Style">

                </form>
                    <?php

            // write variable from text box

            $colFile = "colour.txt";
            fwrite($fh, $colData);
            $fh = fopen($colFile, 'w') or die("can't open file");
            $str = $_POST["hdrCol"];
            $colData = $str;
            fwrite($fh, $colData);
            fclose($fh);

            ?>
        </div>

        <div id="options2" style="height:200px;width:400px;margin:0 auto;background:#666;">
                <form
                    action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

                        <label> Browser Type: </label>
                        <select name="browTy" id="browTy">
                        <option name="browTy" value=" a1 "> Laptop </option>
                        <option name="browTy" value=" a2 "> Mobile </option>
                        </select>
                    </br>
                    </br>

                <input type="submit" name="submitBrow" value="Submit Browser">

                </form>

                        <?php

            // write variable from dropdown

            $myFile = "h1File.txt";
            fwrite($fh, $stringData);
            $fh = fopen($myFile, 'w') or die("can't open file");
            $str = $_POST["browTy"];
            $stringData = $str;
            fwrite($fh, $stringData);
            fclose($fh);

            ?>

        </div>

        <div id="options3" style="height:200px;width:400px;float:right;margin-top:-200px;background:#666;">
            <form
                    action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

                        <label> Encryption Type: </label>
                        <select name="encTy" id="encTy">
                        <option name="encTy" value=" 1 "> Add 1's </option>
                        <option name="encTy" value=" 2 "> Add 2's </option>
                        </select>
                    </br>
                    </br>

                <input type="submit" name="submitEnc" value="Submit Encryption">
            <?php 

                $encFile = "encryption.txt";
                fwrite($fo, $encData);
                $fo = fopen($encFile, 'w') or die("can't open file");
                $enc = $_POST["encTy"];
                $encData = $enc;
                fwrite($fo, $encData);
                fclose($fo);

                ?>
                </form>

I dont understand what exactly you are asking. Since you are writing to three different files, I dont see how it gets overwritten by a different method meant to write to a different file.
However for clearer code, I would suggest that you seperate your PHP from your html. Thus you will have one html file and three PHP files (hdrCol.php,browTy.php and encTy.php) I hope you are familiar with how to go about it. This will make debugging a bliss :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.