Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

checkbox in php

Posted on 2014-12-17
8
Medium Priority
?
36 Views
Last Modified: 2016-05-26
checkbox in php
0
Comment
Question by:surender singh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 672 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 664 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 664 total points
ID: 40505994
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 43

Expert Comment

by:Rob
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 111

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

610 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