Jump to content

Values from unchecked checkboxes?


Tuk

Recommended Posts

Hello. I ran into a hitch today and still haven't been able to find a way around it. I was hoping someone here would see a solution.

 

This script is for a browser-based game that allows users to own animals and feed them, etc. This particular file is where the users assign a food to their animals. It is a form with a loop to display all the animals owned by the user, each with a checkbox that has the animal's id# from the database as the value.

 

Here is the checkbox input within the loop:

<input type=checkbox name="whichanimal[]" value=<? echo $animals['aid'];?>

 

Once they've pressed Submit, this is the script that runs to assign the proper food type (variable obtained from the URL using $_GET):

$update_ids = @implode(",",$_POST['whichanimal']);
$query = @mysql_query("UPDATE animals SET assignedfood = '$foodid' WHERE aid IN ($update_ids)");

 

 

All of this works perfectly fine. My issue is that I want users to be able to uncheck a checkbox and when they submit the form, it 'unassigns' the food (sets it to 0). My problem is that the checkbox is within a loop...

 

My thought was that if there is an opposite command to IN (in the update query), I could use it to get all the animals the user owns who weren't checked and set their assignedfood to 0... Does such a command exist? Is there some other way I'm totally missing? Please let me know if you need anymore info, and thank you in advance for any insight. :)

 

- Tuk

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.