Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Cycle Through Checkboxes


I am fairly new to PHP and ran into a problem that I am sure someone can help me out with. I have a list of email addresses that I am pulling from mySQL, and printing them in table rows with checkboxes in front of each row so that the user can select the address to be deleted from the DB when the user clicks submit button.

I am naming each checkbox "c_<email address>". The output works fine.

The problem that I am having is, how do I make PHP cycle through each of the checkboxes to check to see which one or ones are checked?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Get Back/next Buttons To Cycle Through List Sequentially
I have a portfolio page with a list of clients names. When a client is clicked on, their info is displayed via a function. I want to be able to have a 'back' and 'next' button for each client so users can cycle through the list sequentially. I don't want to duplicate the buttons for every client session, though.

So I need to tell the back and next links what to link to for each client. My attempt at doing this is in the stripped down version of my code, below. Only it doesnt work. If anyone could help me I'd be hugely grateful! If I haven't been clear in my intentions or the code below is gibberish, please let me know and I'll try and explain myself better!! 

Incidentally, the page is called via the site navigation showing the 'clientlist'  function, from which the user can select a client. 'subnav' is also displayed, and this contains the back/next buttons. Code:

SMARTY: Cycle Arguments Loaded From Config File?
I'd like to have the options for my cycle loaded from the config file
if possible. So far I haven't been able to find the right syntax or an
example, any ideas?

ie
<code>
*** config file ***
[index]
color1="#eeeeee"
Color2="#dddddd"

*** tpl ***
{config_load file="test.conf" section="index"}

{section name=members loop=$users}
<tr bgcolor="{cycle values="{#color1#},{#color2#}"} >
<td>{$users[members].id}</td><td>{$users[members].email}</td>
</tr>
{/section}
</code>

Checkboxes
I've got a form with multiple checkboxes (1-1000 depending what you get from database), and all of those checkboxes are named with an unique id: $Id. What I wanna do is when the form is submitted, all of the rows where checkbox is selected will be updated.

I know that it's done by UPDATE TABLE SET Field = 'New Value' WHERE Id IN (1,2,4,8...)

But how can I read what checkboxes are checked, when the name of the checkboxes are changing?

Checkboxes
I have a form with 3 checkboxes wich have all the same name:

<input type=checkbox name=test value=val1>
<input type=checkbox name=test value=val2>
<input type=checkbox name=test value=val3>

now on the target page i need all values that are checked, so if they are all 3 ckecked i need to get val1, val2 and val3 on the target page. With ASP you get the varaible test = val1;val2;val3 (the values are all put in one variable, separated with a ";"

But when i use PhP i only get the last value in this case "val3". What do i need to do to get all values? I have named them all the same because those checkboxes are dynamicly generated. I dont know how many there will be.

Checkboxes
I have a two checkboxes in HTML:

<input TYPE="checkbox" NAME="cc" VALUE="true"></td><td><b>Credit
Card</b></td></tr>

<input TYPE="checkbox" NAME="cash" VALUE="true"></td><td><b>Company
Check</b>

<input type=button onClick='<?php reviewpayment()?>' value='Continue'
style='font: 10pt Arial;

The function works if I type into the function
$cc = true;
$cash = false;

<?php
function reviewpayment() {
$validity = TRUE;
if ($cc && cash) {
echo 'javascript:alert(" Please select ONLY ONE type of payment ");'
$validity = FALSE; }
.................... ?.

Therefore the function is not receiving the input from the check boxes.

How do I structure the script and HTML to send the input cc and cash in HTML
to $cc and $cash in PHP?

PHP Checkboxes
How do I send CHECKBOXES via email through the mail() function in PHP?

Example: You have 67 checkboxes, all with unique names, but only want
to send the ones that were checked.

Mailer: Verifies only 2 of those 67 were checked, so the email only
has 2 checkboxes checked.

Checkboxes
I have it so a user ticks checkboxes with what 6 numbers they chose, and i need it to check it with a list of 12 numbers and when they press submit, if they got any correct, its says how many they got right.

I laso need it to say if someone has selected more than six options. The checkboxes id are the numbers, ie checkbox1, checkbox2, checkbox3 etc up to checkbox20 Code:

Allow Only 3 Checkboxes ?
How can I limit number of maximum selected checkboxes to only 3 if I have total of 10 checkboxes? I need to limit to 3 answers in poll that have 10 answers. I use the following to print checkboxes: PHP Code:

Checkboxes
I'm trying to construct a checkbox array in a survey form where one
of the choices is "No Preference" which is checked by default.

If the victim chooses other than "No Preference", I'd like to uncheck
the "No Preferences" box and submit the other choices to the rest of the
form as an array.

I have most of it worked out, but I'm stuck on an apparent disconnect
between php and javascript.

When I use this code:

Checkboxes ...
I was wondering how to run a query for every check box checked, Ive looked around the net and nothing I've come accross is too usefull.

PHP And Checkboxes
<input type="checkbox" name="approved" id="approved" <?php if($f['enabled'] == "1") echo "checked="checked""; ?>" />

it saves it as a boolean in the Db.. how do I set the bool in the DB?

Checkboxes
I have been trying to learn checkboxes and arrays, and I've finally figured out how to add the checkboxes to the database.

I currently have two forms  addlinks.php and modifylinks.php and I have a dolinks.php that submits my data to the database.

What I would like to do now is on my modifylinks page show a tick in the boxes to show that they have already been added.

At the moment if I dont tick any boxes on modifylinks.php it deletes my previous data, and I have to retick them everytime I do an update. Code:

Checkboxes
I have a contact form that has about 15 checkboxes on it for different interest. I am curious on the best practice for setting up my mysql table to store the info from the form and how to check which one is selected /checked

Checkboxes From A Mysql DB
I'm creating a page that includes check boxes that are dynamically pulled from a MySQL database. I have gotten it to correctly pull up the boxes and name them, but when I make a change and submit, all of the values that were checked are set to 0 instead of 1.

This should print out a checkbox, checked if it is supposed to be, and take an argument to be passed when the user chooses to update the page.

When I submit my form, all of the checkboxes pass a value of zero even when they are checked.
Can you tell me if there is an error in this statement?

print "<td valign='top'>";
print "<input type=checkbox name=checkbox_$cat_name value='checked' $checked[$j]></td>";
print ${"checkbox_".$field_name}." !!!";
print "<td valign='top'>$list_cat_name</td>";

$checked[$j] - contains the value 'checked' or nothing set (correctly) earlier in the file
the checkboxes are named checkbox_(fieldname) [ex: checkbox_food]

The value 'checked' is passed to another file that updates the db.

Checkboxes, Arrays And SQL
I am very new with PHP, so I hope someone can help me: With the help of JPJones, I've managed to write a basic search script querying a MySQL database.

I would like my users to choose which fields they search from, eg search for "red" in field1, field2 and field7 only.

I would use checkboxes for this, using [], eg:
<input type="checkbox" id="field[]" value="field1">Field 1

I understand I would have to split the $field array (on the comma delimiter?) and then use it in my SQL statement. Would it be something like this?

foreach($fieldarray as $key=>$value)
{
$sql = "SELECT * FROM table WHERE $fieldarray[i] LIKE '%$searchword%'";
}

I have no idea of the correct syntax.

Setting Checkboxes
I have a script which iwant to use to check some check boxes based on a query. It does not work partly because some of the code is borrowed and because I'm abit of my depth.
PHP Code:

Checkboxes - Implode
This is my situation: I have an html form that has 4 checkboxes.

<p><input type="checkbox" name="area[]" value="1" checked> Area1<br>
<input type="checkbox" name="area[]" value="2" checked> Area2<br>
<input type="checkbox" name="area[]" value="3" checked> Area3<br>
<input type="checkbox" name="area[]" value="4" checked> All other areas</p>

This array is passed to a php page that runs a query on a mySQL table. The possible values for area in the mySQL table are 1, 2, 3, 4, 5, 6. So, I want to display records that match the appropriate checkboxes except if checkbox 4 is checked I want the value to be 4, 5, and 6. (>=4). I just can't get the implode to do this. The problem is the last. If checkbox 4 is checked it displays records with area=4 and doesn't display records with area =5 and area=6. How could I do this?

Checkboxes And Sql Row Results
I am trying to place a checkbox beside each row that is inputed into the database.

Now this is how I diplay the rows:
print "<br><br>There are $num_rows records.<P>";
print "<table width=500 border=0>
";
while ($get_info = mysql_fetch_row($result)) {
print "<tr>
";
foreach ($get_info as $field)
print " <td><font face=arial size=1/>$field</font></td>
";
print "</tr>
";

How would I go about attaching this:
<input type="checkbox" value="..." name="...">
to the side of each displayed row? Also, how would I assign the row id to the checkbox so that once the box is check and the action initiated the row would be deleted?

Table And Checkboxes
i have a table which basically just displays all the stuff out of a database and a check box at the end which i want 2 be able to if the checkbox is checked update and set broken_links = &#390;' for that id, i can get it 2 change 1 but i want to be able to click like 10 checkboxes and it changes broken_links to 0 for them all Code:

Form Checkboxes
I have a form, a very long form of checkboxes. what I want is the values of these checkboxes that are checked to be queryed on a MySQL database. I'll display some of my form so you get the idea of what it looks like also the url to it so you can check it out fully. Code:

Sql Query From Checkboxes
I'm having a Mysql database with two tables, one table person containing the personal information, and another table profile, with several columns that can be either y or n.
As it is now, from a html form I can enter information in the database, and I edit a persons personal information and profile.

But now I want to be able to find persons based on their profile, so I have a form with a checkbox for each column in the profile table. I want to be able to check off one or more checkboxes, and get the names and id number for the corresponding persons. But invariably I get all the persons in the database as a result. Even when I _don't check any boxes_!
I include the code snippets here: Code:

Count Of Checkboxes (again)
I'm still stuck with this problem. Here's a quick recap/summary :-

1. Page 1:User checks 3 out of 10 checkboxes and submits form to page 2
2. Page 2:Item count shows 3 items. User checks an additional 2
checkboxes and presses Update button. Item count now shows 5 checkboxes
are checked and "New" checkboxes remain checked.
3. Page 2:User is happy and submits form to page 3
4. Page 3:Form items are converted into printable text/data

Pedro Graca very kindly offered a solution using "header('Location:
<URL>')" which very nearly worked however my problem is that the form
data needs to be posted to the page 3 when the user is done (if not for
this then the solution was perfect). Using header() does not post the
data and from what I have read elsewhere there is no way of making it do
this.

I can think of a really ugly solution by way of changing the form's
action to page 3 the first time the Submit (to page 3) button is pressed
and tell the user to press it again to get to page 3 but I don't like
this much.

By the way, I really would prefer to avoid JavaScript.

Dynamic Checkboxes
I am doing a structure of booking on line, and now I Have to make this: when anybody books a place (checkbox) it is inserted in the database (column posti) and it must change from a check box to an image PHP Code:

While(list => Checkboxes
I wanted to print out checkboxes for those which are checked when form is being submitted. Whilst, this is my function: PHP Code:

Forms And Checkboxes
I need some help with manipulating form vars, in particular checkboxes. I currently have a form setup that dynamically creates X number of checkboxes, all named "accept_check_X" where X is the index # of that record from the DB.

When I submit I want to be able to check the status of each checkbox to see if it's set to on or off. Right now I'm using $_POST, but it doesn't seem to contain the checkboxes that were left unchecked. It just has the checkboxes that were checked and submitted.
Is there anyway I can check the status of all the checkboxes from the previous page?

Depending Checkboxes
I have one MySQL table from where I pick project names and then list them in a combo box (menu). Depending on what project a user would pick he would then pick a task, that exists in that project (another table for projects). Concept is quite simple but very hard to implement since internet is stateless.

The simplest way would be to pick a project from the first combo box. Depending on what project I would pick the content of task combo box would be adapted. Maybe this could be done with javascript but I don't know how. Maybe I should forget this concept and do it with step by step picking. New page for each pick.

Checkboxes Php & Javascript
I am generating a set of dynamic checkboxes via php.
I have to check that the uer should atleast check one checkbox. When
there are more then 1 checkbox my javascript works but if there is
only one check box then my javascript doesnt works. My code is
<script>
function deletecheck()
{

for (i=0;i<document.form.elements['projectChecked[]'].length;i++)
{ if(document.form.elements['projectChecked[]'][i].checked==true)
{
return true;
}
}
alert ("Please select a project to delete");
return false;
}
</script>
<form ......onsubmit='return deletecheck();'>
<?php
foreach(.....)
{
echo "<input type='checkbox' name='projectChecked[]'
value='".$projectName."' >";
}
?>

Processing Checkboxes
If I choose more than one item in a checkbox list, PHP feeds back only the last choice. Why? For example, I select 'dogs', 'cats' and 'mice', it sets the variable to 'mice' only.

Handling Checkboxes
i have some problem handling with checkboxes when i try to insert a record.It returns no value. For example, if the student is enrolled to a course, i check the box and i want to store the value 1 and if the student is'nt enrolled, i leave the box empty.
Well, i placed, if ($stdenrol=="") $stdenrol=0; before my insert st.

<INPUT type=checkbox name="std_enrol" value="1"<? if ($stdenrol==1)echo "checked";?>>

So, I think if the checkbox is checked, it returns a value "1" to the table and if it is not checked, it returns a value "0". If i check it and try to insert, it does'nt produce me any error.If i leave it empty, it produces me an error,"conversion error from string."
How can i fix this error. This column can also accept null values.

Checkboxes,conditional
Basically I have what seems to be a very small problem but I am driving ny self mad trying to figure out what the problem is. Here is what I have: I have a form with two checkboxes:

<input type="checkbox" name="medicalcheck" >
<input type="checkbox" name="dentalcheck" >

the form is posting the a php file, decision.php, that simple checks to see if the boxes have been checked and performs an operation in either case. Here is the code:

Using Checkboxes Instead Of A Link
On my site I give users to option to subscribe to certain articles. When
they choose to subscribe the necessary addition is made to the database.
When they go to the Unsubscribe section it lists the articles that they are
subscribed to and gives a link next to it letting them unsubscribe. However,
rather than having the text, I want to have a checkbox instead. Then I want
to have a button at the bottom that when clicked unsubscribes them from any
articles whose checkbox is ticked. This is similar to the way that My eBay
works, if you are still unclear.

Multiple Checkboxes
I am OK using php to process ARRAYS of checkboxes BUT how on earth can you process multiple checkboxes with the SAME name WITHOUT using arrays ?  For example  ...

<input name = "check" type = "checkbox" value = "'value1'"/>
<input name = "check" type = "checkbox" value = "'value2'"/>
<input name = "check" type = "checkbox" value = "'value3'"/>

as opposed to ...

<input name = "check[]" type = "checkbox" value = "'value1'"/>
<input name = "check[]" type = "checkbox" value = "'value2'"/>
<input name = "check[]" type = "checkbox" value = "'value3'"/>

The problem is that you cannot use checkbox arrays (of the form check[]) in javascript. There seems to a conflict of interest here ?

Hide One Of The Checkboxes
is there any way that i would be able to hide one of the checkboxes if it is pulling from a database.

Here is the scenario in my website i have all of the different regions (of my website) listed from 1 - 6 on the database. I have just recently made it so that the users can post in different regions other then the old just one region. My problem is that there is an all in the database table. Normally i would just get rid of it but it would void out all of those posts with the region selected as all. What i need to do is hide or get rid of that all without hurting the web site. Is there any way to do that? here is my code:

Deleting Using Checkboxes
im wanting to delete multiple things from a database using checkboxes, now i know how to use checkboxes in php etc. my question is would this be done using a basic while loop? i mean would i query all the things and then do

while ($check_box == 'ON')
{
do the delete script
}

or is there something more to it?

Checkboxes In Arrays
I have a webpage that I need to collect information from and pass on to a result page. The initial page lists product categories from a MySQL database and the result page should show the price list for those selected products. My problem is that I don't want to create an individual item for each category.  It should be done dynamically so that as the databse is updated, the webpage is automatically updated.

I also want the page to be formatted in a certain way. I need to have checkboxes out beside each dynamically "pulled" product category so that the end-user can select which products they would like to see a price list for.  I am able to get the list to print on the initial screen just like I want, HOWEVER, with the way I've set it up, the checkboxes all have the same name, and therefore can't pass unique data to the result page.

How can I make the checkboxes "automatically" be assigned unique names when they are part of an array of other information? Here is the code that I'm currently using: Code:

How Does Gmail Set Up Their Checkboxes?
After loading several other pages, I can return to the original and find my selection intact.

Checkboxes And Emails
I am trying to build a form that changes the email addresses depending on the checkboxes that are checked. I am at a total loss getting multiple checkboxes to populate the email variable. 

I'm not sure if the checkboxes need differing names or the same name. I get an error that says checkboxes with the same name needs to be in brackets[].  With different names I can't get anything to work.

Updating A DB From Dynamic Checkboxes
I have set up a database as follows: 1 table called screen1 with 2 fields: ID and status
I have code to create a HTML table that checks each status entry for every ID (ID is an auto_increment primary key) and depending on the value of status (whether it is 1 or zero) the code will output some HTML code.

This is for a cinema booking system. I have check boxes so that a user can tick eg: 5 checkboxes and book those 5 seats without having to go back and click a link and book it 1 seat at a time (the way i had it before) However, I cant get this working properly with the checkboxes. here is the code I have so far: Code:

Dynamic Tables And Checkboxes
I am creating a table that will allow users to simply check a box and then have whatever they checked be displayed on another page...its not going as I planned. Here is what I have so far:

Looking For Advice: Checkboxes And Mysql
I am currently working on a project, and I need some advice on a couple of things. I am working on a system that displays records from a database. I have included a checkbox beside each record that is displayed, and the idea is that when the user selects the check box and hits submit, the record will disappear from the list of records, but must not be deleted from the database.

So my main question is what kind of field will I need to add to my database? Some sort of field that has true/false setting? And from this I take it I must perform a check to see if the record is true or false in order to determine whether or not to display it? Code:

Checkboxes And Next/Prev Buttons
I am having this problem i cant understand it. I have been able to create this perfectly working script to output results from the database dynamicly. Each record has a check box next to it so i can select if i want to delete it. I am showing 20 records per page.

Here are the main problems :

1) The numbered pages are shown however the next / prev links that i have created are not outputted.

2) How can i make it delete the selected record/s after pressing submit which i tried to place but it isnt showing up for some reason :-s.

And this is a challenge / extra one for me at least :

3) How can i can i make it remember from one page to another what to delete ? shall i used session if so how to implement them ? Code:

Repeat Region & Checkboxes
Here's what I'm trying to do: I have a simple form for submitting some user choices, and the choices are presented as a recordset with each field using a checkbox to indicate the user's choice. As such, the recordset is embedded within the form. I'm labeling each individual entry of the checkbox array, and everything works fine when I submit the form information...

Except that I have multiple records and I'm displaying them using the Dreamweaver MX repeat region behavior. The records span over multiple pages, and so when i submit the entire form, only the checkbox information from the current page gets sent. What would be the recommended method for passing the checkbox information from other pages as well? Do I need to turn the navigation buttons for the repeat region into individual forms so that they maintain the POST data?

Checkboxes Displayed In Table
I have a query with 40ish results I want to display in a 5 row table with checkboxes but am stumped as to how. PHP Code:

Update Dynamic Checkboxes
I am creating a small e-mail system, where the user can create a various number of e-mailgroups and from another form the user can assign e-mailaddresses to the groups.

First I put the names of the groups into a MySQL table "emailgrouptable" - at the same time I alter another table "emailaddresstable" with the (new)names of the groups.

From the page where the user can add new addresses the names of the groups are presented dynamically based on the table "emailgrouptable" first I get the names of the groups and the total number of the groups. Code:

Displaying Array In Checkboxes
Objective:
User have a multi (20) checkboxes ($notif_empr_city) to select his preferences regarding being informed of new events in cities selected. If user selects one or more cities, the result is imploded into an array($ned_array) stored in the database in the field (notif_empr_city (varchar 255 NOT NULL)). Untill here, no problems with this.

Problem:
The problems start when trying to get this array out of the database in order to check or not (depending if the condition exists) the respective checkboxes again. This to enable the user to select more or unselect his preferences. The code I was using for displaying this array was the following, and isn't displaying any data that exists in the database. What is preventing from checkboxes to get checked ?
Code:

Dymanic Populating Checkboxes
i like to retrieve a value from DB,
accordingly i like to display the checkbox, either checked or not.

Now im able to retrieve the value from DB, i can show even show the
checkbox, but i cant make it checked????

the Code i used to display as follows,

#Require the database class
require_once('../dbinfoinc.php');

#Get an array containing the resulting
record
$query = "SELECT * FROM event";
$result = mysql_query($query);

$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
if(($i % 2) == 0) { $c =
'"TableDetail"' }
else { $c = '"TableDetail2"' }

$event_id=mysql_result($result,$i,"event_id");

$event_name=mysql_result($result,$i,"event_name");

$event_publish=mysql_result($result,$i,"publish");
// if(($event_publish) == 0) {
$event_publish = 'No' }
// else { $event_publish = 'YES'
}
$take_action = 'Delete'
echo "<tr>
<td Class='navText'
align='center' class=$c>$event_id</td>
<td class='navText'
class=$c>$event_name</td>
<td class='navText'
align='center' class=$c><input type='checkbox'
name='publish' if($event_publish==1){'CHECKED'}?></td>
<td class='navText'
align='center' class=$c><a
href='delete_event.php?event_id=$event_id'>$take_action</a></td></tr>";

$i++;
}
?>

Getting List Of Checkboxes And Value In Next Page
Problem is that On the first page I display all other user
with checkbox and give user option to select only two user which he
wants to send message. Tell me please how I'll get those checkboxes
value and name on the next page and send message to only those two
selected user.

Mysql Update And Checkboxes
I'm building a music site with a mysql backend. It has a many to many
relational database.
I use this to match music genres with certain artists, to maintain the
possibility to add multiple genres to a singe artist.

Now i've searched google, but can't find a solution on how to update
rows with checkboxes.
If an artist gets his genre updated as follows:
from

- [_] classic
- [X] rock
- [_] ballad
- [X] 80's
- [_] 90's
- etc.

to

- [_] classic
- [_] rock
- [_] ballad
- [_] 80's
- [X] 90's
etc.

Multiple Checkboxes Help Needed
I'm using MySQL to display data on a web page - fitting about 10
records of data per screen - I'm including a checkbox with each record
so that I can check it and when the submit button is clicked the
called .php script will delete those records that are checked.

I'm creating the records from the table with the checkboxes ok (I
think):

<INPUT TYPE='checkbox'
NAME='frm_chk_delete[$php_delete_counter]'>Delete

I use a php counter var to give each checkbox record item a unique
NAME and this seems to work OK - producing
frm_chk_delete[0]
frm_chk_delete[1]
etc.

The problem I'm having is the POST called script - I don't seem to be
detecting enabled checkboxes to delete them:

$php_mem_name = Trim(StrToLower($php_name));
$php_SQL = "SELECT * FROM basics WHERE member_name =
'".$php_mem_name."'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
$php_delete_counter = 0;
while ($php_row = mysql_fetch_object($php_resultID))
{
if ($frm_chk_delete[$php_delete_counter] == 'on')
{
$php_SQL = "DELETE FROM basics WHERE member_name =
'".$php_mem_name."'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
}
$php_delete_counter++;
}




Copyright © 2005-08 www.BigResource.com, All rights reserved