jeudi 21 avril 2016

How to check if a checkbox returns a value? Error:"Notice: Undefined index:"

I am working on my final project in my final grade. I'm currently working on a site linked with mysql for a dance school. I want to check if a checkbox returns a value or not. It gives a "undefined index"-error at the "if($_POST['dansstijl'.$i.''])" and I don't know what i'm doing wrong.

Sorry if there are parts in dutch!

Here's a big part of the code:

$sql1="INSERT INTO tblinschrijvingen(llnID) VALUES('".$lln_id."')";
   if(!$result1=$mysqli-> query($sql1))
                       {trigger_error('Fout bij query: '.$mysqli->error);}
   else 

   {
       $sql2="SELECT inschrijvingsID FROM tblinschrijvingen ORDER BY inschrijvingsID DESC LIMIT 1";
       if(!$result2=$mysqli-> query($sql2))
                       {trigger_error('Fout bij query: '.$mysqli->error);}
       else 
       {
           for($i=1;$i<=11;$i++)
           {
               if($_POST['dansstijl'.$i.''])
               {
                   $row=$result2->fetch_assoc();
                   $inschrijvingsID=$row['inschrijvingsID'];

                   $sql3="SELECT DansID, vestiging, Dansstijl FROM tbldanslessen WHERE vestiging='".$vestiging."' AND Dansstijl='".$_POST['dansstijl'.$i.'']."'";

                   echo($sql3);
                   if(!$result3=$mysqli-> query($sql3))
                           {trigger_error('Fout bij query: '.$mysqli->error);}
                   else 
                   {
                       $row=$result3->fetch_assoc();
                       $dansID=$row['DansID'];

                        $sql4="INSERT INTO tblinschrijvingenperdansles(inschrijvingsID, dansID) VALUES ('".$inschrijvingsID."', '".$dansID."')";
                        if(!$result4=$mysqli-> query($sql4))
                               {trigger_error('Fout bij query: '.$mysqli->error);}
                       else 
                       { 
                       }
                    }
               }
        }
   }

Here are my checkboxes:

<table border="0">
                            <tbody>
                              <tr>
                                <td width="199"><label>
                                  <input type="checkbox" name="dansstijl1" value="Peuterballet" id="dansstijl1">
                                Peuterballet</label></td>
                                <td width="162"><label>
                                  <input type="checkbox" name="dansstijl2" value="Preballet" id="dansstijl2">
                                Preballet</label></td>
                              </tr>
                              <tr>
                                <td><label>
                                  <input type="checkbox" name="dansstijl3" value="Preprimary" id="dansstijl3">
                                Preprimary</label></td>
                                <td><label>
                                  <input type="checkbox" name="dansstijl4" value="Primary" id="dansstijl4">
                                Primary</label></td>
                              </tr>
                              <tr>
                                <td><label>
                                  <input type="checkbox" name="dansstijl5" value="Klassiek" id="dansstijl5">
                                Klassiek</label></td>
                                <td><label>
                                  <input type="checkbox" name="dansstijl6" value="Modern Jazz" id="dansstijl6">
                                Modern Jazz</label></td>
                              </tr>
                              <tr>
                                <td><label>
                                  <input type="checkbox" name="dansstijl7" value="Hedendaags" id="dansstijl7">
                                Hedendaags</label></td>
                                <td><label>
                                  <input type="checkbox" name="dansstijl8" value="Musical" id="dansstijl8">
                                Musical</label></td>
                              </tr>
                              <tr>
                                <td><label>
                                  <input type="checkbox" name="dansstijl9" value="Pointes" id="dansstijl9">
                                Pointes</label></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr>
                                <td><label>
                                  <input type="checkbox" name="dansstijl10" value="Hiphop - Breakdance" id="dansstijl10">
                                Hiphop - Breakdance</label></td>
                                <td><label>
                                  <input type="checkbox" name="dansstijl11" value="Hiphow - Crew" id="dansstijl11">
                                Hiphow - Crew</label></td>
                              </tr>
                            </tbody>
                          </table>

Thank you on forehand!

Jules




Aucun commentaire:

Enregistrer un commentaire