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

  • SEARCH
  • Home
  • 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 4614522
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:42:42+00:00 2026-05-22T01:42:42+00:00

I am writing a PHP/MySQL application that maintains a masterlist of user preferences and

  • 0

I am writing a PHP/MySQL application that maintains a masterlist of user preferences and I’ve gotten myself stuck trying to remove items from that list. Currently the application generates a list of items and marks a checkbox next to the ones a user has previously selected, the user can then change their selections (either adding or removing checkmarks) and resubmit. The form only submits supplyid’s for items the user has checked.

I have the list sorted so that unmarked selections are shown first and I’ve got the code to insert/update items in the database working, but I’m having problems figuring out how to delete the items the user has unchecked (and which now do not return supplyid’s).

At this point, I’ve written a MySQL query to return only results that were previously included on the list (as those are the only ones which could need to be removed.) What I need are the items in the array returned by the query that do not match any $_POST results. I’ve been successfully comparing the array to the $_POST results of items previously included, but I can see my logic is wrong in the part where I’m trying to get back the results which don’t match. While I’m able to view which items match, I’m not sure how to eliminate them as possibilities. Am I going about this in the wrong way entirely?

$iduser = $_SESSION["iduser"];
$possibleresults = $_POST["possibleresults"];
$sql_onlist = "select supply.idsupply from supply, kit
                    where supply.class = 'basic'
                      and kit.iduser = '".$iduser."'
                      and supply.idsupply = kit.idsupply";

$possible_delete = $connection->query($sql_onlist);

//for each record we know is already in the database, check to make sure it has been checked, otherwise delete
for ($i=0; $i<$possibleresults; $i++) {
$count = 0;
$item_delete = $possible_delete->fetch_assoc();
if ($_POST['item_'.$i.'']) {
    $idsupply = $connection->real_escape_string($_POST['item_'.$i.'']);
//if there is a match, increase the counter
if ($idsupply == $item_delete["idsupply"]) {
    $count++;
    //this does successfully return a count = 1 - idsupply = number for all rows which should have matches
        echo "count = ". $count . " - idsupply = " . $idsupply;
}           
    //this statement doesn't work because it doesn't know which idsupply
    if ($count < 1) {
        $idsupply = $item_delete["idsupply"];
        $sql_delete = "delete from kit 
                  where idsupply = '".$idsupply."'
                  and iduser =  '".$iduser."'";
    $result_delete = $connection->query($sql_delete);   
    }
}
  • 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-05-22T01:42:43+00:00Added an answer on May 22, 2026 at 1:42 am

    Holy moly, what a tangled mess… kinda painted yourself into a corner eh? No worries it happens to all of us. 🙂

    So I think that once you have a truly working algorithm the code just kinda comes together around it. So lets analyze your problem:

    • Your main objective is to store a users settings.

    • You are using a form and checkboxes to both display the current settings and to allow the user to change their current settings. This is graceful enough.

    • Generate a list of the users POSTed settings (aka get the new settings from the POST array) and store those results in a dedicated data container like an array or a linked list.

    • Once you have a list of new settings, you need to use that list as a map to set/unset various fields within a database table.

    • Get a list of ALL of the users saved settings from the database storing that in a different data container

    • Do a case by case comparison, seeing if the variables match, record the results in yet another data container, or do an immediate write to the database.

    • Present the user with a human readable result of their operation.

      NOTE: Incidentally, you probably already know this, but if you use isset($_POST['mychkbox1']) and it returns a positive value, then that checkbox was checked. If isset() returns false, the checkbox was not set, or does not exist. Like I said you probably already knew that, but I figured I toss it in there.

      Good luck

    h

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a new website that uses PHP and MySQL. I am trying
I'm a bit obsessed now. I'm writing a PHP-MYSQL web application, using PDO, that
I'm writing an application in PHP that uses a MySQL database to store information.
I am writing a php application that will post to a mySQL database. I
I'm writing a PHP application that will store STUDENT data in a MySQL relational
I am writing a web app in PHP using mySQL that models an election.
I am writing a web application in PHP that will store large numbers of
I am writing application in PHP (+ MySQL database), but it gonna be mainly
I'm currently writing a PHP application and i noticed that my page loads kinda
I am writing an application where the user inputs song information that will then

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.