Solved

checkbox in php

Posted on 2014-12-17
8
22 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 30

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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 40505994
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 108

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 30

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 30

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now