0

Here is what I tried to do. Please read through as I'll try best to explain my issue as I'm kinda new here.

(1) I have check boxes dynamically created and tried assigning check box name same as one of the data records in the SQL database. i.e there is a table column with the name 'sbstart' and I tried assigning the values of this table row to check boxes as check box name. example, sbstart has 3 rows which contains 1,2,3, so I tried assigning 1,2,3 as check box values. Here's the code for that.

echo "<table cellpadding='2' class='tablet' cellspacing='0'>";
echo 
"<tr>
<th class='tbldecor8'></th>"
."<th class='tbldecor2'>"."Starting Cheque No"."</th>"
."<th class='tbldecor3'>"."Ending Cheque No"."</th>"
."<th class='tbldecor4'>"."Total No of Cheques remaining"."</th>"
."<th class='tbldecor5'>"."Cheque Type"."</th>"
."</tr>";

    while ($reca = mysqli_fetch_array($result))
    {
    if($reca['sbstart'] != "" && $reca['sbend'] !="") {
    $cxVal = $reca['sbstart'];
        echo "<tr>";
        echo "<td class='tbldecor1'><input type='checkbox' name='$cxVal'>$cxVal</td>";
        echo "<td class='tbldecor2' style='text-align:center'>".trim($reca["sbstart"])."</td>";
        echo "<td class='tbldecor3' style='text-align:center'>".trim($reca["sbend"])."</td>";
        echo "<td class='tbldecor4' style='text-align:center'>".trim($reca["totsb"])."</td>";
        echo "<td class='tbldecor5' >SmithKline Beecham (Consumer)</td>";
        echo "</tr>";
        }
}
        echo "<tr class='tbldecor6'></tr>"; 
        echo "</table>";

(2) Please read. Im coming to my issue. Secondly I wanted to check when user submits the form what values are selected through check boxes, get them and delete them. In order to do that to understand what options user has checked I used the following and it always giving 'No' as output.

if(isset($_POST['submit']))
{
    if(isset($_POST['$cxVal'])){echo 'Yes';}else{ echo 'No';}
}

Well if you have a better idea/ correct ways of doing this please share. Thanks.

EDIT:

<html>
<form with PHP SELF......>
<div><?php
echo "<table cellpadding='2' class='tablet' cellspacing='0'>";
echo 
"<tr>
<th class='tbldecor8'></th>"
."<th class='tbldecor2'>"."Starting Cheque No"."</th>"
."<th class='tbldecor3'>"."Ending Cheque No"."</th>"
."<th class='tbldecor4'>"."Total No of Cheques remaining"."</th>"
."<th class='tbldecor5'>"."Cheque Type"."</th>"
."</tr>";

    while ($reca = mysqli_fetch_array($result))
    {
    if($reca['sbstart'] != "" && $reca['sbend'] !="") {
    $cxVal = $reca['sbstart'];
        echo "<tr>";
        echo "<td class='tbldecor1'><input type='checkbox' name='$cxVal'>$cxVal</td>";
        echo "<td class='tbldecor2' style='text-align:center'>".trim($reca["sbstart"])."</td>";
        echo "<td class='tbldecor3' style='text-align:center'>".trim($reca["sbend"])."</td>";
        echo "<td class='tbldecor4' style='text-align:center'>".trim($reca["totsb"])."</td>";
        echo "<td class='tbldecor5' >SmithKline Beecham (Consumer)</td>";
        echo "</tr>";
        }
}
        echo "<tr class='tbldecor6'></tr>"; 
        echo "</table>";

?>
<input type="submit" name="del" id="del" value="Delete">
</div>
</form>
</html>

1 Answer 1

1

Change

echo "<td class='tbldecor1'><input type='checkbox' name='$cxVal'>$cxVal</td>";

To

//input field array
echo "<td class='tbldecor1'><input type='checkbox' name='del[]' value='$cxVal'>$cxVal</td>";

In PHP,

echo "<pre>";
print_r ($_POST['del']); // array of all checked values
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry It seems I cant figure out what ur trying to explain. I've edit my code structure above. can you elaborate it a bit more? thanks
if you have edited as per my answer, then do var_dump($_POST); you will get all checked box values into array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.