 |
| 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
|
|
|
|

March 13th, 2006, 04:05 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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> </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> </td>
<td>Pagination</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="save" value="Save"></td>
<td> </td>
<td> </td>
<td> </td>
<td> </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', '[email protected]', '8063fca5eae470311bcc7c484117a4f5', 'Administrator', '', 'UAS', 'Matyland', 'DC', 'Arra', 'A', 'A', 'A', 1, 5, '', '1141893738');
INSERT INTO `lm_users` VALUES (2, 'editor', 'editor', '[email protected]', '8063fca5eae470311bcc7c484117a4f5', '', '', 'USA', 'L.A', 'VIG', '1', '1', '1', '1', 1, 2, '1135951112', '');
INSERT INTO `lm_users` VALUES (3, 'kamara', 'zaza', '[email protected]', '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, '', '');
|
|
 |