Deletion of an array

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:
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>";
    }
  }
so far so good the viewing part works now
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';
      }  
    }
using the function:
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.
 
:!:
try echoing Message in each function
in get_users echo message Showing
in delete_users echo message Deleing user .......
do like this

dbConnect() or die("No Host/Db connection");
mysql_query(.........) or die ("Sql Problem");
will show that there is some problem in your query

:arrow:
 
see what you do:
Code:
function get_users($username)
{
  if (!($conn = dbconnect()))
    return false;

.....
maby best if you do it:
Code:
function get_users($username)
{
  if (!($conn == dbconnect()))
    return false;

.....
or
Code:
function get_users($username)
{
  if (!$conn)
    return false;

.....
where $conn it's:
Code:
$conn=pconnect($host, $user, $password);
 
may be he is returning value from dbconnect()
:wink: if (!($con=dbconnect()))

doing this. if ($con==dbConnect() ) will match returned value to $con :!: then execute the if statements
 
You should use something like this for deleting

"DELETE FROM table WHERE field = $var && field2 $var"

Then to see the mysql error use the good old

Code:
mysql_query($sql) or die("Delete Error".mysql_error());
 
Back
Top