vendredi 1 mai 2015

Why does this only send me the last selected item and not all selected?

To premise this question, I have only just started learning html, css, javascript and php...

Basically I want all selected checkboxes to send to me (along with other information I haven't included as it works fine)

<?php

$proteins = array(
'Eggs',
'Chicken Breast',
'Turkey Steak',
'Pork Chop',
'Lean Beef Mince',
'Casserole Beef',
'Sirloin Steak',
'Lamb Fillet',
'Venison Steak',
'Tuna',
'Salmon',
'Tilapia',
'Cobbler',
'Cod Fillet',
);

$carbs = array(
'Basmati Rice',
'Sweet Potato',
'CousCous',
'White Potato',
'Brown Pasta',
'Oats',
'Granola',
'Puffed Rice',
'Brown Bread',
'Egg noodles',
'Rice Noodles'
);


$fats = array(
'Almonds',
'Cashews',
'Peanuts',
'Pine Nuts',
'Peanut Butter',
'Almond Butter',
'Olive Oil',
'Avacado',
);

$max = max(count($proteins), count($carbs), count($fats));
$i = 0;



?>



<?php   

    while($i <= $max ){

        if(!isset($proteins[$i])){$proteins[$i] = '';}
        $protein = $proteins[$i];

        if(!isset($carbs[$i])){$carbs[$i] = '';}
        $carb = $carbs[$i];

        if(!isset($fats[$i])){$fats[$i] = '';}
        $fat = $fats[$i];




    echo '
    <tr>';
        if(!empty($protein)){echo '<td style="height: 23px">'.$protein.'<input name="pro_list[]" value="'.$protein.'" type="checkbox"></td>';} else {echo '<td style="height: 23px"></td>';}
        if(!empty($carb)){echo '<td style="height: 23px">'.$carb.'<input name="c_list[]" value="'.$carb.'" type="checkbox"></td>';} else {echo '<td style="height: 23px"></td>';}
        if(!empty($fat)){echo '<td style="height: 23px">'.$fat.'<input name="f_list[]" value="'.$fat.'" type="checkbox"></td>';} else {echo '<td style="height: 23px"></td>';}

    echo '</tr>';
    $i++;
    }


    ?>


<?php   
    $to = "example@gmail.com";

if(isset($_GET['submit'])){

if(!empty($_POST['pro_list'])) {
    foreach($_POST['pro_list'] as $pro) {


    }
}
}

if(isset($_GET['submit'])){

if(!empty($_POST['c_list'])) {
    foreach($_POST['c_list'] as $c) {


    }
}
}

if(isset($_GET['submit'])){

if(!empty($_POST['f_list'])) {
    foreach($_POST['f_list'] as $f) {
    }
    }
}



    $message = '
<table border="1" style="background-color:grey;border-collapse:collapse;border:1px solid #990000;color:#000000;width:auto" cellpadding="3" cellspacing="3">
    <tr>
        <td>Proteins</td>
        <td>'.$pro.'</td>      
    </tr>
    <tr>
        <td>Carbs</td>
        <td>'.$c.'</td>
    </tr>
    <tr>
        <td>Fats</td>
        <td>'.$f.'</td>
    </tr>
</table>'

mail($to,$message);
}
?>




Aucun commentaire:

Enregistrer un commentaire