deleting distinct from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • burgensteen
    New Member
    • Sep 2006
    • 7

    deleting distinct from database

    Hi all,
    New to this forum, so to start 'A big hello to you all'.

    My question:
    I have a drop down menu that is created from the username in my database but is distinct:

    <td><class="tdT ext"><strong><? php echo $lang['admin']['adminusers']['show_emptysess ions'];?></strong></td>
    <td align="right">
    <?
    $query= mysql_query("SE LECT DISTINCT username FROM CubeCart_admin_ sessions");
    echo "<form action=removeby name.php method=POST><se lect name=users>";
    while ($r = mysql_fetch_arr ay($query))
    {
    $user = $r["username"];
    echo "<option value=$user>$us er</option>";
    }
    echo "</select>";
    ?>
    <INPUT TYPE=submit NAME=users VALUE="Go!">
    </form>



    Then my removebyname.ph p file:

    mysql_connect($ glob['dbhost'],$glob['dbusername'],$glob['dbpassword']);
    @mysql_select_d b($glob['dbdatabase']) or die( "Unable to select database");

    // DETERMINE WHICH RECORDS TO DELETE
    $query="SELECT loginid FROM CubeCart_admin_ sessions WHERE username='$user '";
    mysql_query($qu ery);

    //SHOW WHICH RECORDS TO DELETE
    $query="SELECT * FROM CubeCart_admin_ sessions WHERE loginid='$user' ";
    mysql_query($qu ery);

    //DELETE CHOSEN USER RECORD
    $query="DELETE FROM CubeCart_admin_ sessions WHERE loginid='$user' ";
    mysql_query($qu ery);

    //DELETE THE ID COLUMN
    $query="ALTER TABLE CubeCart_admin_ sessions DROP COLUMN loginId";
    mysql_query($qu ery);

    //RECREATE THE ID COLUMN STARTING FROM ONE
    $query="ALTER TABLE CubeCart_admin_ sessions ADD COLUMN loginId INT NOT NULL AUTO_INCREMENT PRIMARY KEY";
    mysql_query($qu ery);

    //PRINT SUCCESS STATEMENT TO SCREEN
    echo "All records relating to $user have been purged successfully";

    mysql_close();
    ?>

    <META HTTP-EQUIV="refresh" content="0;URL= sessions.php">


    The distinct drop down works fine in my session.php file and locates the removebyname.ph p file but just prints the success message (minus the varaible i set) returns to the session.php but nothing is deleted.

    Any ideas my friends ??????
    And thanks for reading.

    Jon
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    How do you know if a mysql statement is executed successfully? You just assume that it is! Set your errors on and investigate the result of each MySql statement. Then you can pinpoint where it went wrong.

    Ronald :cool:

    Comment

    • burgensteen
      New Member
      • Sep 2006
      • 7

      #3
      To be honest, I dont even think the $user isn't being passed to the removebyname.ph p file?????

      I tried echoing $user at the very top of the removebyname.ph p and...Nothing!! !!!

      It gives me the distinct usernames from my login database okay in dropdown ???

      Jon

      Comment

      • LeipePo
        New Member
        • Sep 2006
        • 1

        #4
        Originally posted by burgensteen
        To be honest, I dont even think the $user isn't being passed to the removebyname.ph p file?????

        I tried echoing $user at the very top of the removebyname.ph p and...Nothing!! !!!

        It gives me the distinct usernames from my login database okay in dropdown ???

        Jon
        think your better off with: $_POST['user'] , try googleing for $_GET, $_POST, $_COOKIE, $_SESSION, you will learn alot from it...

        Comment

        • burgensteen
          New Member
          • Sep 2006
          • 7

          #5
          Thanks for the help.
          It was the Get method I needed.
          Thaks again

          Comment

          Working...