I am trying to code a php form that is dynamic. I don't know how many items there will be ahead of time. My plan is the script reads items from a database then displays them with two checkboxes. One for accepting the item, one for deleting it. Now I can get one checkbox to work but not the second one.
What I did was store all the ID numbers in a Session variable and named the Checkbox by the same ID number. In processing I called up each item in that Session variable and read the checkbox that way. The problem is the second checkbox can't be named the same ID number so I tried something like this:
<input type="checkbox" name=D$ID>
then reading it with
$_POST[d$id];
but that doesn't work, any ideas how I can tackle this?
Problem with forms!
Moderator: General Moderators
Re: Problem with forms!
Will multiple checkboxes be available? If so you should name them as arrays so they'll be posted as an array.
Code: Select all
echo '<input type="checkbox" name="name1[' . $yourIdHere . ']">
<input type="checkbox" name="name2[' . $yourIdHere . ']">';Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: Problem with forms!
I am having trouble reading that variable, how should it go?
$_POST['name1[$tmp]'] doesn't seem to work
$_POST['name1[$tmp]'] doesn't seem to work
Re: Problem with forms!
You should read it like this (as it will be an array)
Code: Select all
if (!empty($_POST['name1']))
{
foreach ($_POST['name1'] AS $key => $value)
{
echo $key . ': ' . $value . '<br />';
}
}Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- Bill H
- DevNet Resident
- Posts: 1136
- Joined: Sat Jun 01, 2002 10:16 am
- Location: San Diego CA
- Contact:
Re: Problem with forms!
A couple of things that jumps out at me.
One is that PHP vars are case-sensitive. So name=D$ID is not going to be recognized by $_POST[d$id].
Also, dollar signs are reserved to ondicate a variable, and cannot be used within a variable name.
So "name=did" will be recognized by $_POST['did'] (note the single quotes in the "$_POST" iteration).
One is that PHP vars are case-sensitive. So name=D$ID is not going to be recognized by $_POST[d$id].
Also, dollar signs are reserved to ondicate a variable, and cannot be used within a variable name.
So "name=did" will be recognized by $_POST['did'] (note the single quotes in the "$_POST" iteration).