A
Anonymous
Guest
Here's the problem I retrieve a list a users from my database.
I now want the option to delete each user from my database.
Here's the code I'm using to retrieve the users:
i print them out using this code:
so far so good the viewing part works now
i try to delete them using this code
using the function:
does this code seem logical because i always get a result of "Could not delete" and i don't why it stops at that point. i know it has something to do with passing the array but i don't know how to fix it.
I now want the option to delete each user from my database.
Here's the code I'm using to retrieve the users:
Code:
function get_users($username)
{
//extract from the database all the URLs this user has stored
if (!($conn = dbconnect()))
return false;
$result = mysql_query( "select usrfname, usrlname
from usrinfo
where username = '$username'");
if (!$result)
return false;
//create an array of the URLs
while ($row = mysql_fetch_assoc($result)) {
$usr_array[] = $row;
}
return $usr_array;
}
i print them out using this code:
Code:
if (is_array($usr_array) && count($usr_array)>0)
{
foreach ($usr_array as $usr)
{
echo "<tr bgcolor=$color>
<td>$usr[usrfname] $usr[usrlname]</td>";
echo "<td><input type=checkbox name=\"del_me[]\"
value=\"$usr\"></td>";
echo "</tr>";
}
}
i try to delete them using this code
Code:
if (count($del_me) >0)
{
foreach($del_me as $usr)
{
if (delete_usr($valid_user, $usr))
echo 'Deleted';
else
echo 'Could not delete';
}
}
Code:
function delete_usr($valid_user, $usr)
{
// delete one user from the database
if (!($conn = dbconnect()))
return false;
// delete the user
if (!mysql_query( "delete * from userinfo
where username='$valid_user'
and usrfname='$usr[usrfname]'
and usrlname='$usr[usrlname]' "))
return false;
return true;
}
does this code seem logical because i always get a result of "Could not delete" and i don't why it stops at that point. i know it has something to do with passing the array but i don't know how to fix it.