mercredi 11 septembre 2019

Display checkbox output on different page

Can anyone help me i dont know what to do.. I have a list of checkboxes upon checking the check box and by clicking the submit button i want the output to be displayed on the other php page i've already done the output computation i just dont know how to send of fetch the checked value into another page

<?php
$connect=mysqli_connect("localhost","root","","test");

 $sql = "SELECT * FROM icheck ";
 $result = mysqli_query($connect, $sql);
 //$row = mysqli_fetch_array($result);
?>
//MY FIRST PAGE
<form method="POST">
<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Price</th>
            <th>Check</th>
        </tr>
    </thead>
    <?php
    if(mysqli_num_rows($result)>0){
        $i=1;

    while($row=mysqli_fetch_array($result))
    {
echo'<tr>
    <td>'.$row['id'].'</td>
    <td>'.$row['name'].'</td>
    <td>'.$row['price'].'</td>
    <td><input type="checkbox" name="check[]" value='.$row['id'].'></td>

    ';
    $i++;
    }
    }
        ?>

</table>
<input type="submit" name="submit" Value="Submit"/>
</form>

//OUTPUT TO BE DISPLAYED ON OTHER PAGE or 2nd PAGE
<?php 
if(isset($_POST['submit'])){
if(!empty($_POST['check'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['check']);
echo "You have selected following ".$checked_count." option(s): <br/>";
if(isset($_POST['check'])){
$sum=0;
foreach($_POST['check'] as $selected) {
    $ah="SELECT * FROM icheckWHERE id=".$selected;
    $rowz = mysqli_query($connect, $ah);
    $row=mysqli_fetch_array($rowz);
    echo $row['name']."</br>";
    $test=$row['price'];
    $sum+=(int)$test;

}

echo "Jay Total na ket: ".$sum;
}
}
else{
echo "<b>Please Select Atleast One Option.</b>";
}
}

?>




Aucun commentaire:

Enregistrer un commentaire