-3

I've been stuck with this and have been searching solutions but it still doesn't seem to work could someone help :))

<?php
if(isset($_POST['submit_btn']))
{
$file = fopen("data.txt", "a");

fwrite($file,"in game name :");
fwrite($file, $ingname."\n");
fwrite($file,"firstname :");
fwrite($file, $name."\n");
fwrite($file,"discord name :");
fwrite($file, $dname."\n");
fwrite($file,"main lengend :");
fwrite($file, $mlengend."\n");
fwrite($file,"secondary lengend :");
fwrite($file, $slengend."\n");
fwrite($file,"third legend :");
fwrite($file, $tlengend."\n");
fclose($file);
}
?>

this is the php code in the file config.php

<div class="container">
        <div class="title">Registration</div>
        <form action="/config.php" method="POST">

            <div class="user-details">
                <div class="input-box">
                    <span class="details">In game name</span>
                    <input type="text" name="ingname" placeholder="" required>
                </div>
                <div class="input-box">
                    <span class="details">Firstname</span>
                    <input type="text" name="name" placeholder="" required>
                </div>
                <div class="input-box">
                    <span class="details">Discord username</span>
                    <input type="text" name="dname" placeholder="" required>
                </div>
                <div class="input-box">
                    <span class="details">Main legend</span>
                    <input type="text" name="mlengend" placeholder="" required>
                </div>
                <div class="input-box">
                    <span class="details">Secondary legend</span>
                    <input type="text" name="slengend" placeholder="" required>
                </div>
                <div class="input-box">
                    <span class="details">Third legend</span>
                    <input type="text" name="tlengend" placeholder="" required>
                </div>
            </div>

            <div class="region">
                <p class="questionR">What is your region?</p>
                <select name="select">
                    <option value="Europe" name="regiondata" selected>Europe</option> 
                    <option value="North-America" >North-America</option>
                    <option value="South-America" >South-America</option> 
                    <option value="Africa" >Africa</option>
                    <option value="Asia" >Asia</option> 
                    <option value="Australia" >Australia</option> 
                  </select>
            </div><br>

            <div class="kdascreen">
                <form>
                    <span class="kdaQuest">Please provide a screenshot of your overall stats</span><br>
                    <input type="file" id="kdaUser" name="kdaFile">
                </form>
            </div>
            <br>
            <div class="platform">
                <input type="radio" name="plat" id="dot-1">
                <input type="radio" name="plat" id="dot-2">
                <input type="radio" name="plat" id="dot-3">
                <input type="radio" name="plat" id="dot-4">
                <span class="platform-choice">On what platform do you play on?</span>
                <div class="platform-category">
                    <label for="dot-1">
                        <span class="dot one"></span>
                        <span class="plat">PSN</span>
                    </label>
                    <label for="dot-2">
                        <span class="dot two"></span>
                        <span class="plat">Xbox</span>
                    </label>
                    <label for="dot-3">
                        <span class="dot three"></span>
                        <span class="plat">PC - Mouse and keyboard</span>
                    </label>
                    <label for="dot-4">
                        <span class="dot four"></span>
                        <span class="plat">PC - Controller</span>
                    </label>
                </div>
            </div>

            <div class="rulesTOS">
                <input type="radio" name="choiceMade" id="pot-1">
                <input type="radio" name="choiceMade" id="pot-2">
                <span class="readrules">Have you read the <a href="rules.html" target="_blank">rules</a> and agreed with the <a href="https://tos.ea.com/legalapp/WEBTERMS/US/en/PC/" target="_blank">TOS?</a></span>
                <div class="choice">
                    <label for="pot-1">
                        <span class="pot one"></span>
                        <span class="choiceMade">Yes</span>
                    </label>
                    <label for="pot-2">
                        <span class="pot two"></span>
                        <span class="choiceMade">No</span>
                    </label>
                </div>
            </div>

            <br>
            <div class="button">
                <input type="submit" name="submit_btn" value="submit"/>
            </div>
        </form>
    </div>

this is the form in the file registreren.html I've been messing around and even made this file a php file still didn't seem to work I think I might have made a stupid mistake that might have made it no to work.

#edit

I added the $_POST["xxx"] and gave it reading an writing premissions but still can't seem to save the data to the data.txt file.

<?php
if(isset($_GET['submit_btn']))
{
$file = fopen("data.txt", "a");

fwrite($file,"in game name :");
fwrite($file, $_POST["ingname"]."\n");
fwrite($file,"firstname :");
fwrite($file, $_POST["name"]."\n");
fwrite($file,"discord name :");
fwrite($file, $_POST["dname"]."\n");
fwrite($file,"main lengend :");
fwrite($file, $_POST["mlegend"]."\n");
fwrite($file,"secondary lengend :");
fwrite($file, $_POST["slegend"]."\n");
fwrite($file,"third legend :");
fwrite($file, $_POST["tlegend"]."\n");
fclose($file);

chmod("data.txt", 7777);
}
?>
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Abudew
  • 9
  • 2
  • 1
    "_but it still doesn't seem to work_" meaning what exactly? File's not created? Nothing written to the file? Wrong text written to file? – brombeer Jul 04 '21 at 13:59
  • 1
    Where are your variables set? `$ingname`, `$name` etc – brombeer Jul 04 '21 at 14:00
  • 1
    (1) You are using POST method, so all the variables passed should be $_POST["xxxxxx"]. For example, $ingname should be $_POST["ingname"], etc. (2) make sure that the directory is write-permitted so that the system can create the file – Ken Lee Jul 04 '21 at 14:01
  • @brombeer It doesn't write to the file. – Abudew Jul 04 '21 at 14:34
  • @KenLee I'll add that real quick and see if it works. – Abudew Jul 04 '21 at 14:35
  • I added the $_Post["xxx"] and gave it permissions still didn't do anything – Abudew Jul 04 '21 at 14:54
  • Please do some basic debugging and give us a more detailed explanation of the problem. If you don't know how to do basic debugging, now would be a good time to go and learn - otherwise you will never be able to solve simple issues in your programs. http://www.phpknowhow.com/basics/basic-debugging/ has a simple guide to debugging with PHP. And also ensure you've got error reporting switched on - see [How can I get useful error messages in PHP?](https://stackoverflow.com/questions/845021/how-can-i-get-useful-error-messages-in-php) in case you're simply not seeing the necessary info. – ADyson Jul 04 '21 at 16:19
  • P.S. Having said that though, your edited version still misses one important change: `if(isset($_GET['submit_btn']))` needs to be `if(isset($_POST['submit_btn']))` - clearly that will be submitted as a POST variable along with all the others, it's not an exception. – ADyson Jul 04 '21 at 16:20
  • 1st, the chmod should be done either in linux console / SSH or thru FTP. 2nd, (as ADyson has said), you should use `if(isset($_POST['submit_btn']))` instead of if(isset($_GET['submit_btn'])) – Ken Lee Jul 04 '21 at 23:44

2 Answers2

1
<?php
echo"waiting for submit..."."\n";
if(isset($_POST['submit_btn']))
{
    echo"submitted";
    $file = fopen("data.txt", "a") or die("could not open file");
    echo"in the file";
                                                                                 
    $INGNAME=$_POST['ingname'];
    $NAME=$_POST['name'];
    $DNAME=$_POST["dname"];
    $MLEGEND=$_POST["mlegend"];
    $SLEGEND=$_POST["slegend"];
    $TLEGEND=$_POST["tlegend"];

    fwrite($file,"in game name :");
    fwrite($file, $INGNAME."\n");
    fwrite($file,"firstname :");
    fwrite($file, $NAME."\n");
    fwrite($file,"discord name :");
    fwrite($file, $DNAME."\n");
    fwrite($file,"main lengend :");
    fwrite($file, $MLEGEND."\n");
    fwrite($file,"secondary lengend :");
    fwrite($file, $SLEGEND."\n");
    fwrite($file,"third legend :");
    fwrite($file, $TLEGEND."\n");
    fclose($file);

}
?>

So in the end I figured out that the issue I was having was premission based. I made some changes to the php file. but all I had to do was make the directory it was in not read-only read-only option

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Abudew
  • 9
  • 2
0

I have reviewed my code and found some typos and misplacements in my html code.

---html code---

<form action="config.php" method="post">

            <div class="user-details">
                <div class="input-box">
                    <span class="details">In game name</span>
                    <input type="text" name="ingname" autocomplete="off" required>
                </div>
                <div class="input-box">
                    <span class="details">Firstname</span>
                    <input type="text" name="name" autocomplete="off" required>
                </div>
                <div class="input-box">
                    <span class="details">Discord username</span>
                    <input type="text" name="dname" autocomplete="off" required>
                </div>
                <div class="input-box">
                    <span class="details">Main legend</span>
                    <input type="text" name="mlegend" autocomplete="off" required>
                </div>
                <div class="input-box">
                    <span class="details">Secondary legend</span>
                    <input type="text" name="slegend" autocomplete="off" required>
                </div>
                <div class="input-box">
                    <span class="details">Third legend</span>
                    <input type="text" name="tlegend" autocomplete="off" required>
                </div>
            </div>

            <div class="region">
                <p class="questionR">What is your region?</p>
                <select name="regiondata">
                    <option value="Europe" selected>Europe</option>
                    <option value="North-America">North-America</option>
                    <option value="South-America">South-America</option>
                    <option value="Africa">Africa</option>
                    <option value="Asia">Asia</option>
                    <option value="Australia">Australia</option>
                </select>
            </div><br>

            <div class="kdascreen">
                <span class="kdaQuest">Please provide a screenshot of your overall stats</span><br>
                <input type="file" id="kdaUser" name="kdaFile">
            </div>
            <br>
            <div class="platform">
                <input type="radio" id="dot-1" name="button" value="PSN">
                <input type="radio" id="dot-2" name="button" value="Xbox">
                <input type="radio" id="dot-3" name="button" value="PC">
                <input type="radio" id="dot-4" name="button" value="PC-Controller">
                <span class="platform-choice">On what platform do you play on?</span>
                <div class="platform-category">
                    <label for="dot-1">
                        <span class="dot one"></span>
                        <span class="plat">PSN</span>
                    </label>
                    <label for="dot-2">
                        <span class="dot two"></span>
                        <span class="plat">Xbox</span>
                    </label>
                    <label for="dot-3">
                        <span class="dot three"></span>
                        <span class="plat">PC - Mouse and keyboard</span>
                    </label>
                    <label for="dot-4">
                        <span class="dot four"></span>
                        <span class="plat">PC - Controller</span>
                    </label>
                </div>
            </div>

            <div class="rulesTOS">
                <input type="radio" name="choiceMade" id="pot-1">
                <input type="radio" name="choiceMade" id="pot-2">
                <span class="readrules">Have you read the <a href="rules.html" target="_blank">rules</a> and agreed with
                    the <a href="https://tos.ea.com/legalapp/WEBTERMS/US/en/PC/" target="_blank">TOS?</a></span>
                <div class="choice">
                    <label for="pot-1">
                        <span class="pot one"></span>
                        <span class="choiceMade">Yes</span>
                    </label>
                    <label for="pot-2">
                        <span class="pot two"></span>
                        <span class="choiceMade">No</span>
                    </label>
                </div>
            </div>
            <br>
            <div class="button">
                <input type="submit" class="button" value="Save">
            </div>
        </form>

There was an extra <form> tag in the the <form> tag, this made it the reason it was not sending any information to my php or to the text file.

I have also reworked my php file for it to work properly with all the tags excluding the file one (still working on that part).

---php code---

<?php
    extract($_REQUEST);
    $file = fopen("data.txt", "a");
                                                                                 
    $INGNAME=$_POST['ingname'];
    $NAME=$_POST['name'];
    $DNAME=$_POST['dname'];
    $MLEGEND=$_POST['mlegend'];
    $SLEGEND=$_POST['slegend'];
    $TLEGEND=$_POST['tlegend'];
    $SCREESHOT=$_POST['kdaFile'];
    if(isset($_POST['button'])){
        $PLAT=$_POST['button'];
    }
    $REGIONDATA=$_POST['regiondata'];

    fwrite($file,"In game name :");
    fwrite($file, $INGNAME."\n");
    fwrite($file,"Firstname :");
    fwrite($file, $NAME."\n");
    fwrite($file,"Discord name :");
    fwrite($file, $DNAME."\n");
    fwrite($file,"Main lengend :");
    fwrite($file, $MLEGEND."\n");
    fwrite($file,"Secondary lengend :");
    fwrite($file, $SLEGEND."\n");
    fwrite($file,"Third legend :");
    fwrite($file, $TLEGEND."\n");
    fwrite($file,"Platform :");
    fwrite($file, $PLAT."\n");
    fwrite($file,"Region :");
    fwrite($file, $REGIONDATA."\n");
    fwrite($file, "kdafile :");
    fwrite($file, $SCREESHOT."\n");
    fwrite($file, "-----END-----"."\n");
    fclose($file);
    header("location: registreren.html");
?>

In the end I didn't use the if(isset($_POST['submit_btn'])) as I figured out it was really necessary as I could you the extract methode wich basically worked the same and made me write less ;)).

All the code above is my final coding and shouldn't contain any error (I hope it doesn't because everything works for me except the file saving part but that is something I'm working on).

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Abudew
  • 9
  • 2
  • 1
    Please edit your original answer instead of adding multiple contradictory answers. Glad you fixed it though :-) – ADyson Jul 05 '21 at 09:22