0

I have a problem of which I hope it can be solved really easily as I don't want you guys to have to look through all the code. I am running through a loop which is making variables, but when I use the code I get the error message Notice: Undefined variable: member1 in /home/leerlingen/K1-613-IB/arne.depontieu/public_html/databaseverbinden3error/common.inc.php on line 89 Notice: Undefined variable: member0 in /home/leerlingen/K1-613-IB/arne.depontieu/public_html/databaseverbinden3error/common.inc.php on line 90 1

This is my code:

function processForm() {
    $i = isset( $_POST["rows"] ) ? (int)$_POST["rows"] : 0;
    $errorMessages = array();
    for($x=0;$x<$i;$x++){
        ${"requiredFields".$x} = array("lesuur".$x, "datum".$x, "klasgroep".$x, "leerkracht".$x, "lokaal".$x, "vervanglokaal".$x, "vervanger".$x, "omperking".$x );
        ${"missingFields".$x} = array();
        ${"member".$x} = new Member( array("VERVANGING_ID" => isset($_POST["VERVANGING_ID".$x] ) ? (int) $_POST["VERVANGING_ID".$x] : "", "lesuur" => isset( $_POST["lesuur".$x] ) ? preg_replace( "/[^ \-\_a-zA-Z0-9]/", "", $_POST["lesuur".$x] ) : "", "datum" => isset( $_POST["datum".$x] ) ? preg_replace( "/[^ \-\_a-zA-Z0-9]/", "", $_POST["datum".$x] ) : "", "klasgroep" => isset( $_POST["klasgroep".$x] ) ? preg_replace( "/[^ \@\.\-\_0-9]/", "", $_POST["klasgroep".$x] ) : "", "leerkracht" => isset($_POST["leerkracht".$x] ) ? preg_replace( "/[^ \'\-a-zA-Z0-9]/", "", $_POST["leerkracht".$x] ) : "", "lokaal" => isset( $_POST["lokaal".$x] ) ? preg_replace( "/[^ \'\-a-zA-Z0-9]/", "", $_POST["lokaal".$x] ) : "", "vervanglokaal" => isset($_POST["vervanglokaal".$x] ) ? preg_replace( "/[^\-0-9]/", "", $_POST["vervanglokaal".$x] ) : "", "vervanger" => isset( $_POST["vervanger".$x] ) ? preg_replace( "/[^ \'\-a-zA-Z0-9]/", "", $_POST["vervanger".$x] ) : "", "omperking" => isset( $_POST["omperking".$x] ) ? preg_replace( "/[^ \'\-a-zA-Z0-9]/", "", $_POST["omperking".$x] ) : ""));
    }

    if ( $errorMessages ) {
        showInput();
    } else {
    for($x=0;$x<$i;$x++){
        ${"member".$x}->insert();
    }
    displaySuccess("add_vervangingen.php");
}
teynon
  • 6,775
  • 9
  • 60
  • 97
user3052776
  • 47
  • 1
  • 2
  • 6
  • 7
    I see some wtf programming here – Royal Bg May 10 '14 at 14:30
  • `$memberX` variables are not available inside your function. Pass them as parameters (preferably an array). – Amal Murali May 10 '14 at 14:30
  • @Royal Bg can't agree more :) It is not only the mixture between dutch and english variable identifiers, but using indexed variable names, instead of arrays, duplicating POST parameters cleanup code, instead of making a function and reusing it, etc... – Zlatin Zlatev May 10 '14 at 14:33
  • I know my programming like wtf, but I'm new to it :D – user3052776 May 10 '14 at 14:34
  • 4
    @user3052776: then remember this lection: if you (nearly) ever use variable variables, then you should want to use an array instead. – VMai May 10 '14 at 14:37
  • @user3052776 I don't believe you have posted the relevant code here. Which line is `public_html/databaseverbinden3error/common.inc.php on line 89`? It can't be `${"member".$x}->insert();` because that would be a fatal error. Please post the relevant code. – teynon May 10 '14 at 14:40
  • I thought that was the only part in my code where I was using those variables to be honest. as line 89 is actually just `` And for some reason the code actually updates my database, but I have no clue why it would work with those errors. – user3052776 May 10 '14 at 14:43

0 Answers0