Jump to content

Using a checkbox within a SQL query


hillman1984

Recommended Posts

Hi,

    im kind of new to PHP and was wondering if some one could give me a helping hand.

 

I have an inventory database and work which keeps track of all the different hardware we have. I am attempting to create a quicker way of decommissioning the old hardware without having to shift data between tables in phpmyadmin. My idea is to have a php page showing all the records of the different types of hardware (laptops, desktops, printers, etc), and their details. Each record would have a tick box next to it. The user would then tick the appropriate boxes and click a button to then move all of these records to a decommissioned table.

 

Any ideas on how I would go about this?

Link to comment
Share on other sites

Found this floatinf on the net:

<!--  
Instructive notes: 
   1. to use the     if (isset($_POST['submit']))    construct, the submit button must have a name defined as 'submit' 
   2. if each of the checkboxes has been named with the same name (ie 'fruit')  followed by a pair of square brackets '[]', 
when the form is submitted, the $_POST superglobal will have a variable named $_POST['fruit'] that represents an 
array containing array elements from only those checkboxes that have been checked. 
   3. count() returns the number of elements in an array.  here it returns '0' if no checkboxes are checked.  This could be  
because $_POST['fruit'] is not set, or because $_POST['fruit'] represents an array that has been set but has no elements. 
if we change the if statement to   if (isset($_POST['fruit'])), the statements in the 'if' block are never executed,  
so $_POST['fruit'] is not set and must evaluate to null.  count() accurately returns '0' when its parameter is null. 
   4. the value of each element in the array $_POST['fruit'] is determined by the value attribute of each of the checkboxes. 
   5. note that in the absence of an 'action = "some_script.php" attribute in the form element, the browser reloads this script when the submit button is clicked. 

--> 
<html> 
<head> 
<title>checkbox help</title> 
</head> 
<?php 
if (isset($_POST['submit'])) { 
        $fruit = $_POST["fruit"]; 
   $how_many = count($fruit); 
        echo 'Fruits chosen: '.$how_many.'<br><br>'; 
        if ($how_many>0) { 
                echo 'You chose the following fruits:<br>'; 
        } 
        for ($i=0; $i<$how_many; $i++) { 
                echo  ($i+1) . '- ' . $fruit[$i] . '<br>'; 
        } 
      echo "<br><br>"; 
} 
?> 
<body bgcolor="#ffffff"> 
<form method="post"> 
Choose a fruit:<br><br> 
<input type="checkbox" name="fruit[]" value="apples">apples <br> 
<input type="checkbox" name="fruit[]" value="oranges">oranges <br> 
<input type="checkbox" name="fruit[]" value="peaches">peaches <br> 
<input type="checkbox" name="fruit[]" value="mangos">mangos<br> 
<input type="submit" name = "submit"> 
</form> 
</body> 
<html>

May help!?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.