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
    New Coder
    Join Date
    Jan 2011
    Location
    Slovenia
    Posts
    38
    Thanks
    4
    Thanked 0 Times in 0 Posts

    ajax deletion from database

    Hello
    What I'd like to do is, that when a user presses the "delete" button when deleting a friend, it would delete that friend from the database.
    Current problems:
    • fetching the username from the friend to delete
    • deleting the friend (I'm still a beginner at AJAX)


    should I use a href or a submit button? this is what I have (using a submit button, but I have no idea on how to fetch the specific friends username which needs to be deleted)

    PHP Code:

    while($row2 mysql_fetch_array($qwery))
    {
    $friend $row2['user_username'];
    $pic mysql_query("SELECT * FROM users WHERE username='$friend'");
    $picrow mysql_fetch_assoc($pic);

    echo 
    "<img src='".$picrow['imagelocation']."' width='10%'>"."<br />"."<a href='viewbuddy.php?username=".$row2['user_username']."&page=profile'>".$row2['user_username']."</a>"."<br />"."<input type='submit' value='delete' onclick='deleteBud();'>"."<p />";



    This echoes the friends and a submit button saying "delete".

    what should I do to delete them? do I need a seperate file, like delete.php or something?

    have a nice day

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Imo a more user friendly approach is to have a check box for each friend and the user then checks the check boxes for the friends they want to delete. This way you can delete multiple friends in one go rather than one friend at a time with a delete button for each friend.

    When the friends to delete are all selected, the user can click a Delete selected friends button which then sends the userID linked to each check box to a server side script which then deletes the sent userID's and associated records from the database.

    You can do all this with or without AJAX.

    Reading your post it appears your next step could be working through the w3schools ajax tutorials to get the basics of ajax.

  • #3
    New Coder
    Join Date
    Jan 2011
    Location
    Slovenia
    Posts
    38
    Thanks
    4
    Thanked 0 Times in 0 Posts
    that would be a better approach, you're right.
    I already went through the w3schools ajax tutorial, but it has nothing about deleting (or deleting multiple users, posts, whatever with checkboxes) out of the database. And I want to do it with AJAX because it wouldn't need to refresh the page (I'm doing this website for myself, not a customer or friend).

  • #4
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by oxxiz View Post
    that would be a better approach, you're right.
    I already went through the w3schools ajax tutorial, but it has nothing about deleting (or deleting multiple users, posts, whatever with checkboxes) out of the database.
    The tutorial gives a basic demo on how to retrieve database information using ajax. The concept is the same whether you want to retrieve or delete records - the ajax function sends data to a server side script (PHP, ASP or whatever) which then performs the required tasks on a database and then returns any required data back to the ajax function.

    In the link I posted, there is a schematic diagram of the ajax process which is the same whether you want to retrieve or delete records.

    So in your case, you will need a php script that receives data from either 1 or multiple check boxes or a single delete button. That data (in this case userID's) is then inserted into an sql statement to delete the requested records for the sent userID's.


  •  

    Posting Permissions

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