0

Here is my function :

function check1NumSeries($no_serie){

$reponse = $bdd->query('SELECT * FROM produit');
$check = "false";
while(($produit = $reponse->fetch())AND($check == "false")){
    if ($produit[1] == $no_serie){
        $check = "true";
        $id_error = $produit[1];
    }
} return array($check,$id_error);

};

It says when i do the return array($check,$id_error), that i have an "Notice: Undefined variable: id_error in C:\wamp\www\fonction.php on line 90"

line 90 = the return array();

I don't get it ... what is the problem ?

And my code below is executed correctly, it doens't block but i can see a big orange warning box for this error :/

2
  • and when i do $id_error = $produit[1], it doesn't create the variable ? Commented Jul 18, 2014 at 13:02
  • It seems that if condition isn't working Commented Jul 18, 2014 at 13:02

1 Answer 1

1

$id_error is only defined in your if statement. If you do not enter that control structure it is never defined. You should declare a default value for it so it is always defined before you try to use it:

function check1NumSeries($no_serie){

    $reponse = $bdd->query('SELECT * FROM produit');
    $check = "false";
    $id_error = null;  // default value for that variable
    while(($produit = $reponse->fetch())AND($check == "false")){
        if ($produit[1] == $no_serie){
            $check = "true";
            $id_error = $produit[1];
        }
    } 
    return array($check,$id_error);
};
Sign up to request clarification or add additional context in comments.

1 Comment

yes i know that :D the problem is, when i access to the $check value it shows me "true" and the only way to get that is to be in the "if" condition. So i am in the "if" and soo the $id_error must be declared ? Oo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.