0

I want you to select some informations from a database table, everything its okey but wen I try it for the first time (whene the table is empty) I see this erro on my web page:

Notice: Undefined variable

I have tried if(isset) but it didn t work:

here is my code:

<?php
$select_date = "SELECT mois,annee FROM objectif";
$select_query_date = mysqli_query($conn, $select_date);

if (isset($select_date)) {
    if (mysqli_num_rows($select_query_date) > 0) {
        $mois_date = array();
        $annee_date = array();
        while ($row = mysqli_fetch_array($select_query_date)) {
            if (!isset($row['0'])) $row['0'] = 0;
            $mois_date[] = $row['0'];
            if (!isset($row['1'])) $row['1'] = 0;
            $annee_date[] = $row['1'];
        }

        print_r($mois_date);
    }
}

if (!in_array($mois, $mois_date) && !in_array($annee, $annee_date)) { //---}
Ben
  • 8,894
  • 7
  • 44
  • 80
  • What variable does it say is undefined? The error normally refers to a specific variable or line. – Ben Nov 11 '15 at 17:15
  • youre not providing us with enough information. Your error response is incomplete. Provide all the error message you see, specifically the part where it tells you the line number where the error occurs. Also, this `isset($select_date)` is useless as it will always be set since its a string you are hardcoding. – CodeGodie Nov 11 '15 at 17:21
  • The error is in this line if (!in_array($mois, $mois_date) && !in_array($annee, $annee_date)) – Abderrazzak Talal Nov 11 '15 at 17:25

1 Answers1

0

To test if a key is defined, use array_key_exists('1', $row) : http://php.net/manual/fr/function.array-key-exists.php

Raphaël Vigée
  • 2,048
  • 14
  • 27