Re: Php form & row delete problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have tried this but somehow can not seem to get it working. I have incuded
copy of the pages. thanks in advance for the assistance.

########## start.php ( start page. calls DisplayUser.php with an <iframe>
##########
<?php
include ("include.php");
?>
<table width="95%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>

<td width="85%" valign="bottom"><strong><font color="112c73"><b><font
size="2"><a href="start.php">Administrator Menu</a> > User
Information</font></strong></td>
<td width="15%" valign="bottom">
<div align="right"></div>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="0" align="center" cellpadding="2"
cellspacing="0" bordercolor="CCCCCC">
<tr bgcolor="E3E7F0">
<td width="25%">
<div align="left"><strong>Username</strong></div>
</td>
<td width="25%">
<div align="left"><strong>Password</strong></div>
</td>
<td width="25%">
<div align="left"><strong>Department</strong></div>
</td>
<td width="25%">
<div align="left"><strong>Active</strong></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<iframe id=DisplayUserFrame name="DisplayUseriFrame" src="DisplayUser.php"
width="100%" height="275" scrolling="Auto" frameborder="1" marginwidth="0"
marginheight="0" ></iframe>
</div>
</td>
</tr>
<tr>
<td height="15" colspan="2">
<div align="right"></div>
</td>
</tr>
</table>
<table width="95%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="15%"><div align="left">&nbsp;&nbsp;<a href="DelUser.php"
onClick="if (confirm('Warranty Database:\nAre you sure you like to delete
the selected users\(s\)\?'));"><img src="images/delete.jpg" width="50"
height="17" border=0></a></div></td>
<td width="85%"><div align="right"><a href="UserAddNew.php"><img
src="images/new.jpg" width="50" height="17" border="0"></a></div></td>
</tr>
</table>

########## DisplayUser.php ( connects to db and returns users) ##########

<?php
include ("include.inc");
$connect;
$selectdb;
$active;
?>
<script>
function DoToAll(obj_input)
{ bol_is_checked = (obj_input.checked)?true:false
for (x=0;x<obj_input.form.length;x++)
{ obj_input.form.elements[x].checked = bol_is_checked;
}
}

</script>
<form Name="DisplayUser" action="UserDelete.php" method="Post">
<table width="100%" border="0" cellspacing="0" cellpadding="3"
align="center">
<tr bgcolor="#f0f0f0">
<td width="15%">
<input type="checkbox" name="checkall" onclick="DoToAll(this);"></td>
<td width="85%"><i>Select All</i></td>
</tr>
</table>
<?php

$display_user = mysql_query("select * from acl");
if ($display_user)
{
while ($row = mysql_fetch_array($display_user))
{
echo "<table width='100%' border='0' cellspacing='0'
cellpadding='3'><td><input type=\"checkbox\"
name\"users[{$row[$user_id]}]\"></td>";
echo "<td width='25%'>{$row[username]}</td><td
width='25%'>{$row[password]}</td><td width='25%'>{$row[department]}</td><td
width='25%'>{$act}</td></tr>";
}
}
?>

########## DelUser.php ( deleted user and returns to start.php) ##########

<?php
foreach ($_POST['users'] as $user_id => $value) {
$query = mysql_query('DELETE FROM acl where user_id = ' . $user_id)
// commit query
or die ("could not del user" . mysql_error());
}
echo "Done";
?>

----- Original Message ----- 
From: "Torsten Roehr" <roehr@xxxxxxxxxxx>
To: <php-db@xxxxxxxxxxxxx>
Sent: Friday, June 25, 2004 1:35 PM
Subject: [SPAM]  Re: Php form & row delete problems


> "Vincent Jordan" <vjordan@xxxxxxxxxxxxxx> wrote in message
> news:200406251649.i5PGn0o09385@xxxxxxxxxxxxxxxxxxxxxxxxx
> > I have a table that display's a list of users in a mysql db. In the
table
> I
> > have a echo "<input type="checkbox" name"{$row[$user_id]}">
> > {$row[$username]}, {$row[$password}, {$row[$isactive]};
> >
> > ( this is not the exact code but its pretty close. )
> >
> > What I would like to accomplish is after query and print rows. Each row
> has
> > a check box and if the box is checked and delete button is clicked it is
> > passed to userdel.php which would take the user_id and delete row.
> >
> > Any help would be greatly appreciated.
>
> Write your checkbox the following way:
> echo "<input type=\"checkbox\" name\"users[{$row[$user_id]}]\">";
>
> After submitting $_POST['users'] will be an array containing all selected
> user ids. You can then just loop through and do your delete queries:
>
> foreach ($_POST['users'] as $user_id => $value) {
>     $query = 'DELETE FROM table where user_id = ' . $user_id;
>     // commit query
> }
>
> Hope this helps,
>
> Torsten Roehr
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux