SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: A delete table

  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    A delete table

    I have a web site with registered users.
    They end up in a table where all their info is listed.

    If they leave and delete their registration I have a page that deletes all their fields in that table.
    But before it is deleted I want it to be inserted into a new table that I call table_deleted.

    But when I put that line into my code it just isn't working.
    Guess I'm too tired today to see what's wrong, but guess the great people in this forum can help me out.

    PHP Code:
    mysql_select_db($database_connection$connection);
    $query_rs_del sprintf("SELECT * FROM table_user WHERE user_id = $_SESSION['usr_id']"$colname_rs_del);
    $rs_del mysql_query($query_rs_del$connection) or die(mysql_error());
    $row_rs_del mysql_fetch_assoc($rs_del);
    $totalRows_rs_del mysql_num_rows($rs_del);

    $query "INSERT INTO table_delete (user_id, username, reg_date, deleted) VALUES ('$row_rs_del['user_id']', '$row_rs_del['username']', '$row_rs_del['reg_date']', NOW())";        
    mysql_query($query); 
    And after this the delete part is coming, which is working fine without the above code.

    PHP Code:
    $x $_SESSION['usr_id'];
    $sql "DELETE FROM table_user WHERE user_id = '$x'";
    $result mysql_query($sql) or die(mysql_error());
    header("Location: deleted_user.php"); 

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's issues with the single quotes, try:

    $query = "INSERT INTO table_delete (user_id, username, reg_date, deleted) VALUES ('{$row_rs_del['user_id']}', '{$row_rs_del['username']}', '{$row_rs_del['reg_date']}', NOW())";

    Also be sure to use:
    mysql_query($query) or die(mysql_error()); so any problems are highlighted.

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanx a lot. Now it works.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •