Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:16:33+00:00 2026-06-17T15:16:33+00:00

I’m making a button which deletes an record from a mysql database. I have

  • 0

I’m making a button which deletes an record from a mysql database.

I have made a database with 3 tables, 1: user, 2: activity, 3:user_activity.
In the user_activity you can find the UserID (from user) and ActivityID (from activity).

I have alreade made a script that can add both UserID and ActivityID to the user_activity table. But now i also want a button that remove that “row”.

so i made this javascript code with an onclick function:

$(".deleteActivity").click( function() {

    var user_activityId = $(this).data('activity');

    $.ajax({
        type: "POST",
        url: "delete_activity.php",
        data: {
            activity: user_activityId
        },
        dataType: 'json',
        success: function (data) {          
        }
    });
    $(this).hide(); 
});

And I made this delete_activity.php file:

<?php
  include "connection.php";

  $sql = "SELECT * FROM user WHERE Username = '".$_SESSION['Username']."' ";
  $stm = $db->prepare($sql);
  $result = $stm->execute(array());
  while($row = $stm->fetch(PDO::FETCH_ASSOC)) {
  $userID = $row['UserID'];
  echo $userID;
}

  $sql = "SELECT * FROM user_activity WHERE UserID = '".$userID."' ";
  $stm = $db->prepare($sql);
  $result = $stm->execute(array());
  while($row = $stm->fetch(PDO::FETCH_ASSOC)) {
  echo $row['ActivityID'];
}
?>

And this is the button:

echo '<input type="button" class="deleteActivity"  value="Activiteit verwijderen" data-activity="' . $row['ActivityID'] . '">';

As you can see, don’t delete anything yet, i only “echo” the ID’s so I can see the ID’s and check if those are the right ones.

I want to get the ActivityID from the “activity” on which I puch the button. With this ActivityID an can finish my query:

$sql = "SELECT * FROM user_activity WHERE UserID = '".$userID."' AND ActivityID = ??? ";

I hope everything is clear and that there is someone that can help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:16:34+00:00Added an answer on June 17, 2026 at 3:16 pm

    Use your posted user_activity_id on your query 😀 I don’t know the column name of your user_activity_id, so edit it in your case.

    $userActivityId = filter_input(INPUT_POST, "activity");
    
    $sql = "SELECT * FROM user_activity WHERE UserActivityId = :id";
    $stm = $db->prepare($sql);
    $stm->bindValue( ":id", $userActivityId, PDO::PARAM_INT);
    if($stm->execute())
    {
        $rows = $stm->fetchAll();
        foreach($rows as $row)
        {
             echo $row['ActivityId'];
             break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.