id error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

id error

Post by nite4000 »

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.

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>


I do know this worked before but it dont work now. any one who can correct this and help would be nice.

Thanks
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: id error

Post by social_experiment »

Could you paste the source code (html source) for one of the checkboxes
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: id error

Post by nite4000 »

everything i have i pasted to the board.

this is the chk box here

<input type=checkbox name=del[] id=del value='.$row['id'].'>

its above in the code.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: id error

Post by social_experiment »

Source code for the html page is the code that you can see when you select "view source" from the context menu (right click when using a Windows operating system). I want to see if the values you are selecting from the database is being displayed in the source code;
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply