Connecting Tech Pros Worldwide Help | Site Map

Delete accounts not working

Member
 
Join Date: Jul 2007
Location: UK
Posts: 56
#1: 4 Weeks Ago
I have the following code in my website and it is supposed to delete a user account along with all associated records, however it doesn't delete any of the records, the function is working, beacuse I also have a logout function that gets called afterwards that is working, it just seems to be skipping the delete commands.

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. function delacc(){
  2.       $retrievedusr = $_COOKIE['usrid'];
  3.       $dsql1 = "DELETE FROM mpw_3_5_test_dbase_users WHERE username = $retrievedusr";
  4.       $dresult1 = mysql_query($dsql1);
  5.       $dsql2 = "DELETE FROM mpw_3_5_test_dbase_usc WHERE username = $retrievedusr";
  6.       $dresult2 = mysql_query($dsql2);
  7.       $dsql3 = "DELETE FROM mpw_3_5_test_dbase_notes WHERE username = $retrievedusr";
  8.       $dresult3 = mysql_query($dsql3);
  9.       logout();
  10.     }
P.S. I can't provide a link to the website as it isn't online yet.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: 4 Weeks Ago

re: Delete accounts not working


You should be checking whether your queries executed successfully.

Expand|Select|Wrap|Line Numbers
  1. $query = mysql_query("SELECT * FROM `tbl`;");
  2. if (!$query) {
  3.     printf("Query failed: %s", mysql_error());
  4. }
  5.  
didoamylee's Avatar
Newbie
 
Join Date: Nov 2008
Location: Köln , Deutschland
Posts: 15
#3: 3 Weeks Ago

re: Delete accounts not working


You might want to use more quotes. I think that's the problem here since an username is most likely a string with letters and/or numbers. Mysql doesn't "like" that.

Try this:
Expand|Select|Wrap|Line Numbers
  1. $dsql1 = mysql_query("DELETE FROM mpw_3_5_test_dbase_users WHERE username='".$retrievedusr."'");
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#4: 3 Weeks Ago

re: Delete accounts not working


Quote:

Originally Posted by didoamylee View Post

Expand|Select|Wrap|Line Numbers
  1. $dsql1 = mysql_query("DELETE FROM mpw_3_5_test_dbase_users WHERE username='".$retrievedusr."'");

You don't actually need to separate the string if it's a " string as opposed to a ' string:
Expand|Select|Wrap|Line Numbers
  1. $dsql1 = mysql_query("DELETE FROM mpw_3_5_test_dbase_users WHERE username='$retrievedusr' LIMIT 1");
I also suggest using LIMIT so your queries stop searching once they find one (as I imagine you usernames are unique).
Member
 
Join Date: Jul 2007
Location: UK
Posts: 56
#5: 1 Week Ago

re: Delete accounts not working


Hi guys, sorry for the late reply, it is working perfectly now, thank you for all of your help.
Reply