title: How can I fix "Notice: Undefined variable" in PHP?
body: <p>Code:</p>
  <pre><code>Function ShowDataPatient($idURL)
  {
      $query =&quot; select * from cmu_list_insurance,cmu_home,cmu_patient where cmu_home.home_id = (select home_id from cmu_patient where patient_hn like '%$idURL%')
                       AND cmu_patient.patient_hn like '%$idURL%'
                       AND cmu_list_insurance.patient_id like (select patient_id from cmu_patient where patient_hn like '%$idURL%') &quot;;
  
      $result = pg_query($query) or die('Query failed: ' . pg_last_error());
  
      while ($row = pg_fetch_array($result))
      {
          $hn = $row[&quot;patient_hn&quot;];
          $pid = $row[&quot;patient_id&quot;];
          $datereg = $row[&quot;patient_date_register&quot;];
          $prefix = $row[&quot;patient_prefix&quot;];
          $fname = $row[&quot;patient_fname&quot;];
          $lname = $row[&quot;patient_lname&quot;];
          $age = $row[&quot;patient_age&quot;];
          $sex = $row[&quot;patient_sex&quot;];
      }
      return array($hn, $pid, $datereg, $prefix, $fname, $lname, $age, $sex);
  }
  </code></pre>
  <p>Error:</p>
  <pre><code>Notice: Undefined variable: hn in C:\xampp\htdocs\...
  Notice: Undefined variable: pid in C:\xampp\htdocs\...
  Notice: Undefined variable: datereg in C:\xampp\htdocs\...
  Notice: Undefined variable: prefix in C:\xampp\htdocs\...
  Notice: Undefined variable: fname in C:\xampp\htdocs\...
  Notice: Undefined variable: lname in C:\xampp\htdocs\...
  Notice: Undefined variable: age in C:\xampp\htdocs\...
  Notice: Undefined variable: sex in C:\xampp\htdocs\...
  </code></pre>
  <p>How can I fix that?</p>