Closed Thread Icon

Topic awaiting preservation: Deleting selected (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=27365" title="Pages that link to Topic awaiting preservation: Deleting selected (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Deleting selected <span class="small">(Page 1 of 1)</span>\

 
redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 01-22-2006 20:43

Ok, I've been working on having this control room of mine be able to delete all entrys that are selected (via checkbox). I've finaly got something that works but I'm not 100% sure why it works, and if there is anything wrong with it.

A form containing:

code:
<input type="checkbox" name="deleted_items[]" "value="' . $id . '" />



Is submitted to:

code:
if ($_POST["deleted_items"])
	{
		$deleted_items = join(', ', $_POST["deleted_items"]);
		$query = "DELETE FROM newsTable WHERE id IN ($deleted_items)";
		$result = mysql_query($query);
	}



I guess where I'm most confused is on the input name... how does the HTML name know that is an array? Sorry to be such a pain, if I don't know exactly what every line of code is doing I have trouble sleeping. I can't find the tutorial that lead me to this but I will keep searching and post it if I do.

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-22-2006 21:55

Your HTML doesn't know.
Your PHP does, because of the '[]' attached to the end of the name. Because the brackets are empty, the array keys are set to the default (0,1,2...).

redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 01-24-2006 04:57

Ah, so how come in

code:
$_POST["deleted_items"]

the brackets are not used?

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-24-2006 05:25
quote:

redroy said:

$_POST["deleted_items"]



They are - $_POST [ "deleted_items" ]

=)

The brackets are empty in your HTML because they need to be filled in by the sequential numbers that are automatically inserted by the server side code. In your $POST[] example, you are designating the specific value you are looking for, ie 'deleted_items' which is a key in the $_POST[] array.



(Edited by DL-44 on 01-24-2006 05:26)

redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 01-24-2006 19:55

Oh man... I guess I need to read up on $_POST[] and arrays. I really haven't done anything that uses arrays so they confuse me just a bit. Thanks for all your help DL... you've been awesome.

« BackwardsOnwards »

Show Forum Drop Down Menu