I am unable to get the array values after clicking submit in php

I have an html table that displays certain rows, and each row consists of an email id. I kept a check=box at the end of each row. So user can check any of the check-boxes and click ‘send email’ button. On submitting an email has to pop up with all the selected emails ids in the ‘TO’ field.

As of now, I am trying to get the values into an array, and trying to display them. This is for my reference. After that I want to add the mail sending feature.

But my problem is, after checking some check-boxes and clicking submit, my selected emails are not being displayed. It is directly displaying the content in ‘else’, saying ‘no emails are selected’. Thanks in advance.

My code( part of) in html table display page is

$i=-1;
if($result222->num_rows > 0){
//echo '<table cellpadding="0" cellspacing="0" border="1" class="db-table">';
$rowcount=mysqli_num_rows($result222);

echo '<table width="100%" id="tblData1" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" border="1" class="tablesorter"   boarder-collapse ="collapse">';

echo '<thead><tr bgcolor = "#58B0EB"><th>STUDENT_NAME</th><th>ID_NUMBER</th><th>PHONE_NUMBER</th><th>BRANCH</th><th>YEAR</th><th>CONTACT_PERSON</th><th>EMAIL_ID</th><th>NOTES</th><th><form action="sendemail.php" method="POST"><br/><input id="chk" type="checkbox" name="sel_desel"> </th></tr></thead>';
while($rowz222 = mysqli_fetch_assoc($result222)){

echo "<tr>";



foreach($rowz222 as $key=>$value){


if($key=='ci_email') {

$i=$i+1;
echo '<td><a href="mailto:'.$value.'">'.$value.'</a></td>';
$email[]=$value;

}



else{
echo '<td>',$value,'</td>';



}

}
echo '';


echo '<td><input id="checkbox" type="checkbox"  name="checklist[]" value=" ' .$email[$i]. '">';
echo $email[$i];

echo '</td>';

echo '</tr>';

My code in ‘sendemail.php’ is

<?php
    session_start();



        if(isset($_POST['checklist'])){

    $arr=$_POST['checklist'];



        echo "The following email addresses have been selected:<br />"; 

            foreach($arr as $selected) 
            { 
                echo $selected; 

            } 




        }


    else {
    echo 'no emails selected';
    }
?>

Leave a comment