Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 13th, 2006, 04:05 AM
Authorized User
 
Join Date: Feb 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default How 2 store checkboxes values in MySQL

hi all,
I'm trying to make my own CMS components that can show the users with their privillages, I mean each user can have one or more than one privillages (e.g. can add, search ... etc).
BUT, I could show the users BUT not able to store the checkboxes to the database if its checked or not. help here please.
I want it like this:
[img]
http://www.arab-x.com/uploads/Mar-06/3d6c84aba6.jpg
[/img]

Code:
<?php  
 defined( '_VALID_LM' ) or die( 'Direct Access to this location is not allowed.' ); 
 global $conn; 

 if(isset($save)){ 
 echo "Hi !"; 
 $p_search = $_POST['search']; 
 $p_add = $_POST['add']; 
 $p_edit = $_POST['edit']; 
 $p_delete = $_POST['delete']; 

 $username = $_POST['username']; 
 foreach ($username as $usernamex) 
       $query = "UPDATE lm_users SET p_search = '$p_search', 
          p_add = '$p_add', 
          p_edit = '$p_edit', 
          p_delete = '$p_delete'  
          WHERE username = '$usernamex'";  
       $result = mysql_query($query) or die ("query not made");  
 } 
?> 
<table width="100%" border="0" cellspacing="2" cellpadding="2"> 
 <tr> 
   <td> 
<table width="100%" border="0" cellspacing="2" cellpadding="2"> 
<tr> 
   <td width="30%">Enter the user name:</td> 
   <td width="40%"><input name="textfield" type="text" size="25" maxlength="25"></td> 
   <td width="30%"><input type="submit" name="Submit" value="Search"></td> 
 </tr> 
</table> 
</td> 
 </tr> 
 <tr> 
   <td>Editing options </td> 
 </tr> 
 <tr> 
   <td> 
<form method="POST" action="index.php?option=fishylist&action=ucp"> 
<table width="100%" border="1" cellspacing="0" cellpadding="2"> 
 <tr> 
   <td width="3%">Del</td> 
   <td colspan="2">Details</td> 
   <td colspan="4">Privillages</td> 
 </tr> 
 <tr> 
   <td>&nbsp;</td> 
   <td width="30%">name</td> 
   <td width="30%">branch</td> 
   <td width="10%">Search</td> 
   <td width="10%">Add</td> 
   <td width="10%">Edit</td> 
   <td width="10%">Delete</td> 
 </tr> 
  <?php      
 $rs=$conn->Execute("SELECT * FROM lm_users"); 

 if(($row_total=$rs->RecordCount()>0) && $rsa=$rs->GetArray() ) { 
 $row_total=$conn->RecordCount(); 
 foreach($rsa as $row) {     
?> 
 <tr> 
   <td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="<? //echo $rows['id']; ?>"></td> 
   <td><?php echo $row['username']; ?></td> 
   <td><?php echo $row['userbranch'];?></td> 
   <td><input type="checkbox" name= "search[]" value="1" <?php if ($row['p_search'] == 1) {echo "checked";} ?>></td> 
   <td><input type="checkbox" name= "add[]" value="1" <?php if ($row['p_add'] == 1) {echo "checked";} ?>></td> 
   <td><input type="checkbox" name= "edit[]" value="1" <?php if ($row['p_edit'] == 1) {echo "checked";} ?>></td> 
   <td><input type="checkbox" name= "delete[]" value="1" <?php if ($row['p_delete'] == 1) {echo "checked";} ?>></td> 
 </tr> 
  <?php } }?> 
 <tr> 
   <td>&nbsp;</td> 
   <td>Pagination</td> 
   <td>&nbsp;</td> 
   <td>&nbsp;</td> 
   <td>&nbsp;</td> 
   <td>&nbsp;</td> 
   <td>&nbsp;</td> 
 </tr> 
 <tr> 
   <td>&nbsp;</td> 
   <td>&nbsp;</td> 
   <td><input type="submit" name="save" value="Save"></td> 
   <td>&nbsp;</td> 
   <td>&nbsp;</td> 
   <td>&nbsp;</td> 
   <td>&nbsp;</td> 
 </tr> 
</table> 
</form> 
</td> 
 </tr> 
</table>
Code:
CREATE TABLE `lm_users` (
 `id` int(10) NOT NULL auto_increment,
 `name` varchar(50) NOT NULL default '',
 `username` varchar(25) NOT NULL default '',
 `email` varchar(100) NOT NULL default '',
 `password` varchar(100) NOT NULL default '',
 `usertype` varchar(25) NOT NULL default '',
 `userauth` varchar(5) NOT NULL default '',
 `usercountry` varchar(30) NOT NULL,
 `usercity` varchar(30) NOT NULL,
 `userbranch` varchar(30) NOT NULL,
 `p_search` varchar(4) NOT NULL default '1',
 `p_add` varchar(1) NOT NULL default '1',
 `p_edit` varchar(1) NOT NULL default '0',
 `p_delete` varchar(1) NOT NULL default '0',
 `published` int(1) NOT NULL default '1',
 `gid` int(3) NOT NULL default '1',
 `registerDate` varchar(20) NOT NULL default '',
 `lastvisitDate` varchar(20) NOT NULL default '',
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;

-- 
-- Dumping data for table `lm_users`
-- 

INSERT INTO `lm_users` VALUES (1, 'Administrator', 'admin', 'admin@mysite.com', '8063fca5eae470311bcc7c484117a4f5', 'Administrator', '', 'UAS', 'Matyland', 'DC', 'Arra', 'A', 'A', 'A', 1, 5, '', '1141893738');
INSERT INTO `lm_users` VALUES (2, 'editor', 'editor', 'ss@ss.com', '8063fca5eae470311bcc7c484117a4f5', '', '', 'USA', 'L.A', 'VIG', '1', '1', '1', '1', 1, 2, '1135951112', '');
INSERT INTO `lm_users` VALUES (3, 'kamara', 'zaza', 'aaa@aaa.com', '8063fca5eae470311bcc7c484117a4f5', '', '', 'UK', 'London', 'Bur', '1', '1', '0', '0', 1, 1, '1135952472', '');
INSERT INTO `lm_users` VALUES (4, '', 'Xiao Xiao', '', '', '', '', 'USA', 'Florida', 'Hawaya', '1', '1', '1', '1', 1, 1, '', '');
INSERT INTO `lm_users` VALUES (5, '', 'Shayma', '', '', '', '', 'UK', 'Winston', 'Su', '1', '1', '1', '1', 1, 1, '', '');
INSERT INTO `lm_users` VALUES (6, '', 'Edward', '', '', '', '', 'UK', 'Manch', 'Marina', '1', '1', '1', '1', 1, 1, '', '');





Similar Threads
Thread Thread Starter Forum Replies Last Post
how many items can mysql store? yulin11 MySQL 1 December 6th, 2007 11:58 AM
peoblem with checkboxes values shrisangeeta Classic ASP Basics 3 August 19th, 2006 02:03 AM
Delete records in MySQL using checkboxes in forms taslim Beginning PHP 2 August 10th, 2006 05:01 AM
Store Checkbox values in MySQL Database jkilgore Beginning PHP 1 July 7th, 2005 03:43 PM
Cannot store multiple form selections to a mysql d scifo Beginning PHP 2 August 3rd, 2003 04:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.