Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Wrong ID when $_Get

    Hello

    i use this code to delete users from mysql tabel , all ok but when click name it deletes wrong user . the last member gets deleted ..dont know why .. but . i use PHP paased in Javascript to call the id . and it does call id but wrong id .

    get Rows. for mysql
    PHP Code:
    $result mysql_query("SELECT * FROM ".$DB->prefix("users")."  WHERE level=0 ");
    $rows mysql_num_rows($result); 
    PHP Code:
     <script type="text/javascript">
    <!--
      function confirmation3() {
        var answer = confirm("<? echo "are u sure ? "?>")
        if (answer){

            window.location = "user.php?action=st&id=".$row['id']."";
        }
        else{
            alert("<? echo "Canceled"?>")
        }
    }
    //-->
      </script>
    delete link
    PHP Code:
    <a href='#' onclick='confirmation3(); return false;'>delete</a
    do delete

    PHP Code:
     $id HtmlSpecialchars($_GET['id']);
    $query mysql_query("DELETE FROM ".$DB->prefix("users")." WHERE id='$id'")
      or die(
    "cant users"); 
    the thing is if i dont use the href in javascript all work ok just like

    PHP Code:
    <a href=user.php?action=st&id=".$row['id'].">delete</a

  • #2
    New Coder
    Join Date
    Jul 2009
    Location
    Internet
    Posts
    37
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Hi. In your function confirmation3() you've messed Javascript code with PHP code. This line need to be fixed:

    Your version:
    Code:
            window.location = "user.php?action=st&id=".$row['id']."";
    Must be like this:
    Code:
            window.location = "user.php?action=st&id=<?php echo $row['id'] ?>";

  • #3
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Sergey Popov View Post
    Hi. In your function confirmation3() you've messed Javascript code with PHP code. This line need to be fixed:

    Your version:
    Code:
            window.location = "user.php?action=st&id=".$row['id']."";
    Must be like this:
    Code:
            window.location = "user.php?action=st&id=<?php echo $row['id'] ?>";
    Thx
    But i had it like that
    PHP Code:
    =<?php echo $row['id'?>";
    and did not work , did not even replace the Vairble to the actual id # so i changed to
    PHP Code:
    =".$row['id'].""; 
    then that worked and that replaced with the ID it just was wrong id ..

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by onasre View Post
    Thx
    But i had it like that
    PHP Code:
    =<?php echo $row['id'?>";
    and did not work , did not even replace the Vairble to the actual id # so i changed to
    PHP Code:
    =".$row['id'].""; 
    then that worked and that replaced with the ID it just was wrong id ..

    Your not defining what user you want to delete.
    are you posting the information from another page ? or is there more code from that page?

    is this for an admin/mod panel or for the user to delete theyer own acount?
    Last edited by IamHe; 10-13-2009 at 06:57 PM.


  •  

    Posting Permissions

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