Delete accounts not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wangers16
    New Member
    • Jul 2007
    • 57

    Delete accounts not working

    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:

    Code:
    function delacc(){
    	  $retrievedusr = $_COOKIE['usrid'];
    	  $dsql1 = "DELETE FROM mpw_3_5_test_dbase_users WHERE username = $retrievedusr";
    	  $dresult1 = mysql_query($dsql1);
    	  $dsql2 = "DELETE FROM mpw_3_5_test_dbase_usc WHERE username = $retrievedusr";
    	  $dresult2 = mysql_query($dsql2);
    	  $dsql3 = "DELETE FROM mpw_3_5_test_dbase_notes WHERE username = $retrievedusr";
    	  $dresult3 = mysql_query($dsql3);
    	  logout();
    	}
    P.S. I can't provide a link to the website as it isn't online yet.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You should be checking whether your queries executed successfully.

    Code:
    $query = mysql_query("SELECT * FROM `tbl`;");
    if (!$query) {
        printf("Query failed: %s", mysql_error());
    }

    Comment

    • didoamylee
      New Member
      • Nov 2008
      • 16

      #3
      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:
      Code:
      $dsql1 = mysql_query("DELETE FROM mpw_3_5_test_dbase_users WHERE username='".$retrievedusr."'");

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        Originally posted by didoamylee
        Code:
        $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:
        Code:
        $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).

        Comment

        • wangers16
          New Member
          • Jul 2007
          • 57

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

          Comment

          Working...