0

I'm new to php I'm having problems with my code

well the idea of ​​my site is to take the value typed in the fields and create a folder and generate the files with these values ​​inside.

but I have two problems the first one I want to compare if there is within the ids folder in all files the random id of 4 digits and if so generate another one if not, create a file with username and email.

my other problem is to create the folder with the username and id if and create the other files inside, but an error occurs saying the value number not found

( ! ) Warning: A non-numeric value encountered in C:\wamp64\www\rank\reg.php on line 156

and the second mistake occurs in all variables.

( ! ) Notice: Undefined variable: progress6 in C:\wamp64\www\rank\reg.php on line 153

as well as i'm new to php i thought i'd ask for help since i spent a lot of time trying to solve this.

See my code:

    </p-->
            <?php
            if (isset($_GET['run'])){
            run();
            }
            function run(){
            //globais
            $username = $_GET['usernamesave'];
            $userxp = $_GET['userxp'];
            $userid = $_GET['userid'];
            $userlevel = $_GET['userlevel'];
            $usermail = $_GET['usermail'];
            $progresso1 = $_GET['userprog1'];
            $progresso2 = $_GET['userprog2'];
            $Progresso3 = $_GET['userprog3'];
            $Progresso4= $_GET['userprog4'];
            $Progresso5 = $_GET['userprog5'];
            $Progresso6 = $_GET['userprog6'];
            $Progresso7 = $_GET['userprog7'];
            $Progresso8 = $_GET['userprog8'];
            $proceed = $_GET['proceed'];
            //especific
            $nameidf = $username + $userid;
            //generate a rand value
            $randger= rand() % 9000 + 1000;
            $randfix = randger;
            //verify into folder if existe into any file the id , if yes then generete new random
        //  $tokens = ['_twitter_sess', 'ct0', 'auth_token'];
            $tokens = $randger;
            foreach (glob(getcwd() . './usersaccounts/ids/*.txt') as $file) {
            $pointer = fopen($file, 'r');
            while (!feof($pointer)) {
            $line = fgets($pointer);

            foreach ($tokens as $token) {
            if (strpos($line, $token) !== false) {
                //$row[] = $line;
                $randger= rand() % 9000 + 1000;
                $randfix = $randger;
                break;
                }else{
                $fp = fopen('/usersaccounts/ids/' + $username + $email + '.txt' , 'w');
                fwrite($fp, $randfix);
                fclose($fp);
                }
                
                }
            }}
            
            if ($username = null){
                echo "<script>alert('Campo nome de usuario void');</script>";
            }else{
                mkdir("'/usersaccounts/$nameidf");
                $fp = fopen('/usersaccounts/' + $nameidf + '/username.txt' , 'w');
                fwrite($fp, $username);
                fclose($fp);
            if ($userxp = null){
                echo "<script>alert('Campo nome de xp void');</script>";
            }else{
                $fp = fopen('/usersaccounts/' + $nameidf + '/xp.txt' , 'w');
                fwrite($fp, $userxp);
                fclose($fp);
                
            if ($userid = null){
                echo "<script>alert('Campo nome de id void');</script>";
            }else{
                $fp = fopen('/usersaccounts/' + $nameidf + '/id.txt' , 'w');
                fwrite($fp, $userid);
                fclose($fp);
            if ($userlevel = null){
                echo "<script>alert('Campo nome de level void');</script>";
            }else{
                $fp = fopen('/usersaccounts/' + $nameidf + '/level.txt' , 'w');
                fwrite($fp, $userlevel);
                fclose($fp);
            if ($usermail = null){
                echo "<script>alert('Campo nome de mail void');</script>";
            }else{
                $fp = fopen('/usersaccounts/' + $nameidf + '/email.txt' , 'w');
                fwrite($fp, $usermail);
                fclose($fp);
            if ($progresso1 || $progresso2 || $progresso3 || $progresso4 || $progresso5 || $progresso6 || $progresso7 || $progresso8 = null){
                echo "<script>alert('Campo nome de progress void');</script>";
            }else{
                $fp = fopen('/usersaccounts/' + $nameidf + '/progresso1.txt' , 'w');
                fwrite($fp, $progresso1);
                fclose($fp);
                
                $fp = fopen('/usersaccounts/' + $nameidf + '/progresso2.txt' , 'w');
                fwrite($fp, $progresso2);
                fclose($fp);    
                
            }
            }
            }       
            }   
            }   
            }
            }
            
            
                ?>
                
                
                <div class="container">
        <!--h2 class="text-center"><p class="stat-cards-info__num">Salvando Mostrando</p></h2><hr-->
        <div class="row">
        
        
        <label for="usernamesave">Nome de usuario:</label>
        <input id="usernamesave" type="text"></input>
        <hr>
        <label for="userxp">Minha Experiêcia:</label>
        <input id="userxp" type="text"></input>
        <hr>
        <label for="userid">Meu TagID User:</label>
        <input id="userid" type="text"></input>
        <hr>
        <label for="userlevel">Level da Minha Conta:</label>
        <input id="userlevel" type="text"></input>
        <hr>
        <label for="usermail">Meu email pessoal:</label>
        <input id="usermail" type="text"></input>
        <hr>
        <label for="userprog1">Meu uso Progress01:</label>
        <input id="userprog1" type="text"></input>
        <hr>
        <label for="userprog2">Meu uso Progress02:</label>
        <input id="userprog2" type="text"></input>
        <hr>
        <label for="userprog3">Meu uso Progress03:</label>
        <input id="userprog3" type="text"></input>
        <hr>
        <label for="userprog4">Meu uso Progress04:</label>
        <input id="userprog4" type="text"></input>
        <hr>
        <label for="userprog5">Meu uso Progress05:</label>
        <input id="userprog5" type="text"></input>
        <hr>
        <label for="userprog6">Meu uso Progress06:</label>
        <input id="userprog6" type="text"></input>
        <hr>
        <label for="userprog7">Meu uso Progress07:</label>
        <input id="userprog7" type="text"></input>
        <hr>
        <label for="userprog8">Meu uso Progress08:</label>
        <input id="userprog8" type="text"></input>
        <hr>
        <label for="proceed">Proseeguir pra sav</label>
        <input id="proceed" type="text"></input>
        <hr>
        <a href="?run"><button>Run</button></a>

i'm using php version: 5.6.2

  • Welcome to SO. The error msgs you quote tell you the line numbers to check. We can't tell which lines they are, but here are some observations: 1) `$nameidf = $username + $userid;` - this is probably related to your first error, `+` is not how you [concatenate strings in PHP](https://www.php.net/manual/en/language.operators.string.php). 2) `Notice: Undefined variable: progress6 in ...` - `progress6` does not appear anywhere in your code, so either that's an error in some code you haven't shown us, or you typed out the error and made a typo (copy-pasting code/errors is safer); – Don't Panic Nov 20 '21 at 09:58
  • 3) `mkdir("'/usersaccounts/$nameidf");` includes an unbalanced single-quote and likely throws an error too; 4) None of your ``s have names, so [none of those values will be sent](https://stackoverflow.com/questions/12543848/does-form-data-still-transfer-if-the-input-tag-has-no-name) in any form submission. 5) Your form is not actually a form, and is not submitted. Your `?run` button is simply a link, all that does is browse away from the current page. If you want to submit the data in your inputs, [you need a form](https://www.php.net/manual/en/tutorial.forms.php). – Don't Panic Nov 20 '21 at 10:06
  • I would suggest starting out with some tutorials, even the PHP docs have small chunks of example code for each piece of the puzzle. – Don't Panic Nov 20 '21 at 10:07

0 Answers0