hillman1984 Posted August 10, 2009 Share Posted August 10, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/169612-using-a-checkbox-within-a-sql-query/ Share on other sites More sharing options...
jarvis Posted August 10, 2009 Share Posted August 10, 2009 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!? Quote Link to comment https://forums.phpfreaks.com/topic/169612-using-a-checkbox-within-a-sql-query/#findComment-894868 Share on other sites More sharing options...
phporcaffeine Posted August 10, 2009 Share Posted August 10, 2009 Do you have a a custom interface or are you tring to modify the phpMyAdmin interface? Quote Link to comment https://forums.phpfreaks.com/topic/169612-using-a-checkbox-within-a-sql-query/#findComment-894870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.