Solved

checkbox in php

Posted on 2014-12-17
8
28 Views
Last Modified: 2016-05-26
checkbox in php
0
Comment
Question by:surender singh
8 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 168 total points
ID: 40504846
Checkbox is the same in php as it is in html

<input type="checkbox" name="" value="">
0
 
LVL 31

Assisted Solution

by:Marco Gasi
Marco Gasi earned 166 total points
ID: 40504889
Checkboxes in php are submitted only if checked. So if you have a form with one checkbox and when the user submit the form the checkbox is unchecked, it wont appear in the array $_POST (or $_GET).
If the problem is to pass several checkboxes which have the same function within your form, then you have to call them uing array notation. Suppose you have a table and you want the user be able to select which records he wants to edit, you have to call each checkbox, for instance, 'recordToEd[]' and give it a value which holds the record id:

while ($row = mysqli->_fetch_assoc($result))
{
  echo  "<tr><td><input type='checkbox' name='recordToEdit[]' value='" . $row['id'] . "' /> </td>...other columns here ... </tr>";
}

Open in new window


When you submit the form you can get the checkboxes this way:
if (isset($_POST['recordToEdit']) && is_array($_POST['recordToEdit']))
{
  foreach ($_POST['recordToEdit'] as $record)
  {
    $recordsToEdit = $record;
  }
}

Open in new window


In the recordsToEdit array you'll get all the id of the record the user want to edit.

Hope this is what you need to know (and to have not forget something...)

Cheers
Marco
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 40505994
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 41607271
I've requested that this question be closed as follows:

Accepted answer: 250 points for GaryC123's comment #a40504846
Assisted answer: 250 points for marqusG's comment #a40504889

for the following reason:

No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- Gary (http:#a40504846)
-- Marco Gasi (http:#a40504889)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

tagit
Experts-Exchange Cleanup Volunteer
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 41607272
If anybody still cares about the quality of the answers in the PAQ, E-E hould probably have a PHP subject-matter expert look at these.  #40504846 doesn't say anything useful.  #40504889 gives a code example with a logic error that will overwrite a variable multiple times processing only the last element of the array.  The cited article shows the correct answer, with tested-and-working code examples.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 41608168
I agree with Ray: my code should have been
if (isset($_POST['recordToEdit']) && is_array($_POST['recordToEdit']))
{
  foreach ($_POST['recordToEdit'] as $record)
  {
    $recordsToEdit[] = $record;
  }
}

Open in new window

1
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 41608740
My recommendation is to awrd point to the comment #a40505994 for the reasons listed in comment #a41607272
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question