$_POST and checkbox
Moderator: General Moderators
$_POST and checkbox
People...
On my site I have about 20 checkboxes. On every that checkbox is a name and the checked value is 1. Now, when I submit, I want PHP to print strings of checkboxes (not names) that I have activated.
I don't want that to solve by arrays.
I had that problem also with listboxes, and I solved this by databases. I want to solve the checkboxes also by databases but I don't know how...
Please, help...
Thanks.
On my site I have about 20 checkboxes. On every that checkbox is a name and the checked value is 1. Now, when I submit, I want PHP to print strings of checkboxes (not names) that I have activated.
I don't want that to solve by arrays.
I had that problem also with listboxes, and I solved this by databases. I want to solve the checkboxes also by databases but I don't know how...
Please, help...
Thanks.
If you don't want to use arrays for whatever not understandable reason you have to hardcode the stuff.
Code: Select all
if (isset($_POST['checkbox1'] )) {
//do something here
}
if (isset($_POST['checkbox2'] )) {
//do something here
}
.
.
.Yeah... I know how to do this with if...then.
I think you don't understand me, I don't want the name of my checkbox to be "id[]" or something like this.
I have an idea to put all checkboxes in an array (array: 0=>checkbox1, 1=>checkbox2 ...), and then for each element in an array to do some code.
Thanks for fast answers.
I think you don't understand me, I don't want the name of my checkbox to be "id[]" or something like this.
I have an idea to put all checkboxes in an array (array: 0=>checkbox1, 1=>checkbox2 ...), and then for each element in an array to do some code.
I am making a database, and the first site is the site where the data is filled in, and the second step is for checking the data that is filled in. And then the data is put in a database.Also, give us some more info... where is this information going to go? is it like an online quiz, a database, an emailer... what?
Thanks for fast answers.
I am confused now. You contradict yourself. Use arrays not use arrays. You mix this around.
if you use name="id[]" your checkboxes are put in the array $_POST['id'] that you can process on the next page.
I think your logic error is to set the value of the checkbox all to 1. This does not make sense. You put a name like "checkbox1" into the value field.
Every checked checkbox is found in the array $_POST['id'] and with a foreach you can get all the names of the checked checkboxes. As simple as that.
There is a good tutorial in the tutorial section
if you use name="id[]" your checkboxes are put in the array $_POST['id'] that you can process on the next page.
I think your logic error is to set the value of the checkbox all to 1. This does not make sense. You put a name like "checkbox1" into the value field.
Every checked checkbox is found in the array $_POST['id'] and with a foreach you can get all the names of the checked checkboxes. As simple as that.
There is a good tutorial in the tutorial section
Now, I managed somehow to make the code:
Some variables in the code are in Croatian, but it is no matter.
Now when I execute the code it writes me: Unknown column 'abc' in 'where clause'.
I don't see the problem.
In the "karakteristike" table i have id, name and string, id's are auto increment, and names are like the array above. The strings are what I have to write down.
Yes, maybe I am a complicated person, but I am somehow "experimenting", I ve seen that code on an another site, and now I want to make that also.
However, thanks.
Code: Select all
<?php
$array = array("abc","abs","ads","alufelge","asd","asr","esp","ets","4wd","sportovjes","tuned");
foreach ($array as $value) {
if (isset($_POST[$value])) {
$post = $_POST[$value];
}
mysql_select_db($database_db_aoglasnik, $db_aoglasnik);
$query_rs_karakteristike = "SELECT string FROM karakteristike WHERE name = $value";
$rs_karakteristike = mysql_query($query_rs_karakteristike, $db_aoglasnik) or die(mysql_error());
$row_rs_karakteristike = mysql_fetch_assoc($rs_karakteristike);
$totalRows_rs_karakteristike = mysql_num_rows($rs_karakteristike);
if ($post == 1) {
echo "$row_rs_karakteristike".", ";
}
}
?>Now when I execute the code it writes me: Unknown column 'abc' in 'where clause'.
I don't see the problem.
In the "karakteristike" table i have id, name and string, id's are auto increment, and names are like the array above. The strings are what I have to write down.
Yes, maybe I am a complicated person, but I am somehow "experimenting", I ve seen that code on an another site, and now I want to make that also.
However, thanks.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland