id error
Posted: Mon Apr 09, 2012 11:18 am
I have a populated table that is populated by the database. I have the setup so a chk box can be chked and they press delete and it removed the record.
The problem is it dont work its return id=A and i do not know where A is comming from when it should be a number representing an id of a record.
Here is my php and html code.
Here is the html
I do know this worked before but it dont work now. any one who can correct this and help would be nice.
Thanks
The problem is it dont work its return id=A and i do not know where A is comming from when it should be a number representing an id of a record.
Here is my php and html code.
Code: Select all
if ($_POST['justdel_x'])
{
$id = $_POST['del'];
$total_pending = 0;
for ($i = 0; $i < count($id); $i++)
{
$query = "SELECT amount FROM withdrawals WHERE status = 'Pending' AND user_id = {$_SESSION['admin_id']} AND id = {$id[$i]}";
$total_pending += $result['amount'];
$query = "DELETE FROM withdrawals WHERE id = {$id[$i]}";
mysql_query($query);
}
$query = "UPDATE accounts
SET total_wd = total_wd - $total_pending,
acct_balance = acct_balance + $total_pending
WHERE user_id = {$_SESSION['admin_id']}";
mysql_query($query);
}
Here is the html
Code: Select all
<table width="100%" align="center" class="menu_border">
<tr>
<td height="24" colspan="6" class="news_text_hdr">Pending Cashout Summary</td>
</tr>
<tr>
<td width="85" height="21"><img src="../images/form_icons/vcard.png" width="16" height="16" /> Cashout Id</td>
<td width="112"><img src="../images/form_icons/user.png" width="16" height="16" /> Username</td>
<td width="110"><img src="../images/form_icons/money.png" width="16" height="16" /> Amount</td>
<td width="106"><img src="../images/form_icons/calendar.png" width="16" height="16" /> Date</td>
<td width="105"><input type="checkbox" name="checkall" onclick="checkUncheckAll(this);"/></td>
</tr>
<?php
$query = "SELECT * FROM withdrawals WHERE status='Pending' AND user_id = {$_SESSION['admin_id']}";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>{$row['ref_num']}</td>";
echo "<td>{$row['username']}</td>";
echo "<td>{$row['amount']}</td>";
echo "<td>{$row['date']}</td>";
echo '<td><input type=checkbox name=del[] id=del value='.$row['id'].'></td>';
echo "</tr>";
}
?>
<tr><td colspan="6">Total Cashout: $<?php
$r = mysql_query("Select SUM(tot_amt) as total_amount from withdrawals WHERE username='{$_SESSION['admin_user']}' AND status='Pending'") or die(mysql_error());
if (@mysql_num_rows($r) == 0)
{
echo '0.00';
}
else
{
while ($wd = mysql_fetch_array($r, MYSQL_ASSOC))
{
echo '' . $wd['total_amount'] . '';
}
}
?>[ <input name="justdel_x" type="submit" id="justdel_x" value="Delete"> ]</td></tr>
</table>
</form>
Thanks