0

I'm trying to dynamically create a checkbox list using employees from my database. The list is for the purpose of taking attendance at meetings. I tried using a solution I found on this site to create the list but I'm getting an error that there is an unexpected end in my code. I can't find it.

<?php
   $servername = "localhost";
   $username = "root";
   $password = "password";
   $dbname = "purpletrainer";

   // Create connection
   $conn = new mysqli($servername, $username, $password);

   // Check connection
   if ($conn->connect_error) {
       die("Connection failed: " . $conn->connect_error);
   } 
   //echo "Connected successfully";

   $MeetingID = $_POST["meetingid"];

   $sql = "SELECT employee.emplname
           FROM purpletrainer.employee, purpletrainer.meeting
           WHERE employee.empmngrid=meeting.meetingleader
           AND meetingid='$MeetingID'";

       $result = $conn->query($sql);

       //Iterate over the results that you've gotten from the database
       if ($result->num_rows > 0){
               while($employee = $result->fetch_assoc())
               {
               ?>
                       <div>
                               <form action="processlist.php" method="post">
                               <span><?php echo $employee['emplname']; ?></span>
                               <input type="checkbox" name="employees[]" value= '<?php echo $employee[0]; ?>' /><br />
                               </form>
                       </div>
               }

           }

3 Answers3

0

You need to terminate your PHP code properly:

....
</form>
</div>
<?
    }
}
?>
Webomatik
  • 844
  • 7
  • 7
0

at the end of your code you need one additional PHP tag for the closing }, it is currently printed as HTML

bucketman
  • 463
  • 6
  • 15
0

Actually have not complete your while loop and if bracket syntax error. Your if condition code replace with below code.

if ($result->num_rows > 0){
               while($employee = $result->fetch_assoc())
               {
               ?>
                       <div>
                               <form action="processlist.php" method="post">
                               <span><?php echo $employee['emplname']; ?></span>
                               <input type="checkbox" name="employees[]" value= '<?php echo $employee[0]; ?>' /><br />
                               </form>
                       </div>
            <?php
               }

           }
           ?>
Denis Bhojvani
  • 817
  • 1
  • 9
  • 18