hi. i'm seeking help with checkboxes.i have built a ordering system. i have two tables "food" and "refreshments" both consists of columns "name,price" . what i want to do is . if i click on my submit button , all the checked checkboxes should be added up and have a grand total. my problem that i have now is that. when i submit all the prices are added up , but it should only add the checked ones. please help me.
here is how my tables look like
food
food_id name price
1 bunny chow 15
2 chicken 56
refreshments
refresh_id name price
1 coke 13
2 fanta 15
and here is what i have done. "orders.php"
<?php
require_once('mySQLConnect.php');
if(isset($_REQUEST['placeOrder'])) {
$sql2 = " select sum(price) as totalamount from food ";
$q = mysqli_query($conn,$sql2);
$row2 = mysqli_fetch_array($q);
$total = $row2['totalamount'];
echo $total;
}
?>
<html>
<head>
<title>
orders
</title>
<link rel="stylesheet" href="joomla.css">
<script src="jquery-1.7.1.min.js"></script>
<script src="packaged.min.js"></script>
<script src="jquery-ui-1.8.17.min.js"></script>
<script type="text/javascript" src="overlib_mini.js"></script>
<script type="text/javascript" src="Placeholders.js"></script>
<style>
input[type="number"] {
width:50px;
}
input[type="checkbox"] {
width:100px;
height:20px;
}
#buttonCancel {
background : url("img/Cancel.png") no-repeat center center;
height :48px;
width : 48px;
border : none;
color : transparent;
font-size : 0;
white-space: nowrap;
display:inline
}
#buttonAccept {
background : url("img/Check.png") no-repeat center center;
height :48px;
width : 48px;
border : none;
color : transparent;
font-size : 0;
white-space: nowrap;
display:inline
}
</style>
</head>
<body>
<form name="form1" id="form1" method="post">
<div id="dialog-form" style="border: 3px; border-bottom-color: #877d78">
</div>
<table border="0" cellspacing="5" cellpadding="5" width="90%">
<tbody>
<tr>
<td>
<table class="table_title" style="background-color: #71bf44;" border="0" cellspacing="10" cellpadding="0" width="100%">
<tbody>
<tr>
<td align="CENTER" valign="middle">ORDER Menu</td>
<td align="CENTER" valign="middle"><input type="submit" id="buttonAccept" name="placeOrder"><input type="reset" id= "buttonCancel" name="confirm"></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="5" cellpadding="5" width="90%">
<tbody>
<tr>
<td>
<table class="table_title" style=" background-color:#666;"" border="0" cellspacing="10" cellpadding="0" width="25%">
<tbody>
<tr>
<td align="CENTER" valign="middle">food</td><td><br>
</tr>
</tbody>
</table>
<table border="0" cellspacing="5" cellpadding="5" width="90%">
<tbody>
<tr>
<td>
<table>
<thead style="background-color: #71bf44; color: white;" border="0" cellspacing="1" cellpadding="1" width="100%">
<th width="2%" height="5">Item name</th>
<th width="2%" height="5">Price</th>
<th width="2%" height="5">Quantity</th>
<th width="2%" height="5">Select item</th>
</thead>
<tbody>
<?php
$sql = "Select * from food";
$rs = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_assoc($rs)) {
$k=('1');
if ($k==1) {
$k=0;
echo'<tr style="background-color: #d5e6d9" height=30px>';
}else{
$k=1;
echo '<tr height=30px>';
}
echo '<td width="2%" height="5">'. $row['name']. '</a></td> ';
echo '<td width="2%" height="5">R'. $row['price'].'</td>';
echo '<td width="2%" height="5"><input type="number" name="quantity"></td>';
echo '<td width="2%" height="5"><input type="checkbox"></td>';
echo '</tr>';
}
?>
</tbody>
</table>
<table border="0" cellspacing="5" cellpadding="5" width="90%">
<tbody>
<tr>
<td>
<table class="table_title" style="background-color:#666;" border="0" cellspacing="10" cellpadding="0" width="25%">
<tbody>
<tr>
<td align="CENTER" valign="middle">refreshments</td><br>
</tr>
</tbody>
</table>
<table border="0" cellspacing="5" cellpadding="5" width="90%">
<tbody>
<tr>
<td>
<table>
<thead style="background-color: #71bf44; color: white;" border="0" cellspacing="1" cellpadding="1" width="100%">
<th width="2%" height="5">Item name</th>
<th width="2%" height="5">Price</th>
<th width="2%" height="5">Quantity</th>
<th width="2%" height="5">Select item</th>
</thead>
<tbody>
<?php
$sql = "Select * from refreshments";
$rs = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_assoc($rs)) {
$k=('1');
if ($k==1) {
$k=0;
echo'<tr style="background-color: #d5e6d9" height=30px>';
}else{
$k=1;
echo '<tr height=30px>';
}
echo '<td width="2%" height="5">' . $row['name']. '</a></td> ';
echo '<td width="2%" height="5">R'. $row['price'].'</td>';
echo '<td width="2%" height="5"><input type="number" name="quantity"></td>';
echo '<td width="2%" height="5"><input type="checkbox"></td>';
echo '</tr>';
}
?>
</form>
</body>
</html>