-
Jun 25th, 2014, 01:40 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Unable to check the Checkboxes with Database Values
Hi,
I am unable to check the checkboxes using database values. mu database table is as under
Name: useraccess
uid - int
allowaccess - varchar
url - varchar
Values in the table
uid allowaccess url
1 New User Page ----
1 User Management -----
2 Add Accounts ------
2 View Ledger
3 View Ledger
my code is as under
Code:
<?php
session_start();
$id=$_GET['uid'];
//Getting Data from users of the selected user
include_once ('../conn.php');
$sql="Select uname, ulevel, fullname, uid from users where uid = '".$id."'";
$res=mysql_query($sql,$con);
$row=mysql_fetch_array($res);
//Getting Data from USERACCESS table
$sql="Select * from useraccess where uid = '".$id."'";
$res=mysql_query($sql,$con) or die('Error: ' . mysql_error());
$access=mysql_fetch_array($res);
/* while ($access=mysql_fetch_array($res))
{
echo "<h2>" . $access[1] . "</h2>";
}
*/
if($_POST['submit'])
{
include_once ('../conn.php');
$sid=$_POST['tuid'];
$chkd = $_POST['chk'];
for ($i=0; $i<sizeof($chkd); $i++)
{
$sql="insert into useraccess values('".$sid."', '".$chkd[$i]."', '".$chkd[$i]."')";
$res=mysql_query($sql,$con) or die("Error " . mysql_error(). "<br>");
echo $chkd[$i]."<br>";
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Assign Roles</title>
<link href="../styles.css" rel="stylesheet" type="text/css" />
<link href="../CheckBoxStyle.css" rel="stylesheet" type="text/css">
<style>
fieldset {
margin-top:10px;
border-radius:10px;
box-shadow:5px 5px 5px black;
width:95%
}
legend {
background-color:#6CF;
color:#006;
text-transform:uppercase;
border: 1px solid black;
border-radius: 5px;
padding-left:8px;
padding-right:8px;
font-size:small;
}
</style>
</head>
<body>
<?php include('header.php'); ?>
<!-- START content div -->
<div style="width:900px; height:600px; border:1px solid navy; margin:0 auto; margin-top:10px;
background-color:lightsteelblue;box-shadow:5px 5px 5px black; ">
<!-- START Heading DIV -->
<div style="width:200px; border-radius: 0px 0px 10px 10px; margin:0 auto;;
box-shadow:5px 5px 5px black; background-color:white; color:navy; ">
<p style="text-align:center;font-size:20px">Assign Access</p>
</div>
<!--END Heading DIV -->
<div style="border:1px solid white; padding-left:15px; margin-top:10px; width:95%;
margin-left:8px; box-shadow:5px 10px 10px black;">
<table style="width:95%;">
<tr>
<td style="color:#009; font-weight:bold; width:70px">User Name:</td> <td><?php echo $row[0]; ?></td>
<td style="color:#009; font-weight:bold; width:70px">User Level:</td> <td><?php echo $row[1]; ?></td>
<td style="color:#009; font-weight:bold; width:70px">Full Name:</td> <td><?php echo $row[2]; ?></td>
</tr>
</table>
</div>
<div style="margin-top:20px; width:95%; padding-left:15px;">
<form name="frmassignrole" action="assignrole.php" method="post">
<!-- placing a hidden value for the selected user, will be used in saving data -->
<input type="hidden" name="tuid" value="<?php echo $row[3]; ?>" />
<fieldset>
<legend>User Management</legend>
<input type="checkbox" id="chk[]" name="chk[]" value="New User"
<?php if($access[1]=='New User'){?> checked="Checked" <?php } ?> />New User
<input type="checkbox" id="chk[]" name="chk[]" value="User Management"
<?php if($access[1]=='User Management'){?> checked="Checked" <?php } ?> />User Management
</fieldset>
<fieldset>
<legend>Accounts Management</legend>
<input type="checkbox" id="chk[]" name="chk[]" value="Add Accounts"
<?php if($access[1]=='Add Accounts') {?> checked="checked" <?php }?>/>Add Accounts
<input type="checkbox" id="chk[]" name="chk[]" value="Opening Balance"
<?php if($access[1]=='Opening Balance') {?> checked="checked" <?php }?>/>Opening Balance
<input type="checkbox" id="chk[]" name="chk[]" value="View Ledger"
<?php if($access[1]=='View Ledger') {?> checked="checked" <?php }?>/>View Ledger
</fieldset>
<fieldset>
<legend>Inventory Management</legend>
</fieldset>
<fieldset>
<legend>Voucher Management</legend>
</fieldset>
<fieldset>
<legend>Cheque Management</legend>
</fieldset>
<fieldset>
<legend>Reports</legend>
</fieldset>
<input type="submit" id="btnsubmit" name="submit" value="Submit" class="button" />
<span><?php $show ?></span>
</form>
</div>
<!-- END content div -->
</body>
</html>
please suggest ..
-
Jun 27th, 2014, 11:15 PM
#2
Thread Starter
Fanatic Member
Re: Unable to check the Checkboxes with Database Values
DONE it by putting the database values to array, and search the arry while CHECK the checkbox. Check the below code with green color
Code:
<?php
session_start();
$id=$_GET['uid'];
//Getting Data from table users of the selected user
include_once ('../conn.php');
$sql="Select uname, ulevel, fullname, uid from users where uid = '".$id."'";
$res=mysql_query($sql,$con);
$row=mysql_fetch_array($res);
//Getting Data from USERACCESS table
$sql="Select * from useraccess where uid = '".$id."'";
$qry=mysql_query($sql,$con) or die('Error: ' . mysql_error());
$count=mysql_num_rows($qry);
if ($count >=1)
{
while ($a = mysql_fetch_array($qry))
{
$ary=$a[1];
$myvals[]=$ary;
}
}
/* while ($access=mysql_fetch_array($qry))
{
echo "<h6>" . $access[1] . "</h6>";
}
*/
if($_POST['submit'])
{
include_once ('../conn.php');
$sid=$_POST['tuid'];
$chkd = $_POST['chk'];
//Deleteing the old data for the selected user
if ($count >= 1)
{
$sql="Delete from useraccess where uid = '".$sid."'";
$res=mysql_query($sql,$con) or die("Error :" . mysql_error());
}
for ($i=0; $i<sizeof($chkd); $i++)
{
$sql="insert into useraccess values('".$sid."', '".$chkd[$i]."', '".$chkd[$i]."')";
$res=mysql_query($sql,$con) or die("Error " . mysql_error());
// echo $chkd[$i]."<br>"; /Show saved data
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Assign Roles</title>
<link href="../styles.css" rel="stylesheet" type="text/css" />
<link href="../CheckBoxStyle.css" rel="stylesheet" type="text/css">
<style>
fieldset {
margin-top:10px;
border-radius:10px;
box-shadow:5px 5px 5px black;
width:190px;
height:190px;
background-color:white;
padding-top:15px;
padding-bottom:15px;
line-height:25px;
text-align:left;
}
legend {
background-color:#CCC;
color:#006;
text-transform:uppercase;
border: 1px solid black;
border-radius: 5px;
padding-left:4px;
padding-right:4px;
font-size:small;
/*text-shadow:2px 2px black;*/
}
</style>
<script language="JavaScript">
function selectAll() //Check all Checkboxes
{
checkboxes = document.getElementsByName('chk[]');
//alert(checkboxes.length);
/*for(var i in checkboxes)
checkboxes[i].checked = 'checked';*/ //taken from net
for(var i=0; i <=checkboxes.length; i++)
checkboxes[i].checked = 'checked';
}
function unselectAll() //Uncheck all checkboxes
{
checkboxes = document.getElementsByName('chk[]');
for(var i=0; i <=checkboxes.length; i++)
checkboxes[i].checked = '';
}
</script>
</head>
<body>
<?php include('header.php'); ?>
<!-- START content div -->
<div style="width:900px; height:620px; margin:0 auto; margin-top:10px;
background-color:lightsteelblue;box-shadow:5px 5px 5px black; border-radius:10px; ">
<!-- START Heading DIV -->
<div style="width:200px; border-radius: 0px 0px 10px 10px; margin:0 auto;;
box-shadow:5px 5px 5px black; background-color:white; color:navy; ">
<p style="text-align:center;font-size:20px">Assign Access</p>
</div>
<!--END Heading DIV -->
<div style="border:1px solid white; padding-left:15px; margin-top:10px; width:95%;
margin-left:8px; box-shadow:5px 10px 10px black;">
<table style="width:95%;">
<tr>
<td style="color:#009; font-weight:bold; width:70px">User Name:</td> <td><?php echo $row[0]; ?></td>
<td style="color:#009; font-weight:bold; width:70px">User Level:</td> <td><?php echo $row[1]; ?></td>
<td style="color:#009; font-weight:bold; width:70px">Full Name:</td> <td><?php echo $row[2]; ?></td>
</tr>
</table>
</div>
<div style="margin-top:20px; width:95%; padding-left:125px; text-align:center; border:2px solid red;">
<form name="frmassignrole" action="assignrole.php" method="post">
<!-- placing a hidden value for the selected user, will be used in saving data -->
<input type="hidden" name="tuid" value="<?php echo $row[3]; ?>" />
<fieldset style="float:left;">
<legend>User Management</legend>
<input type="checkbox" id="chk[]" name="chk[]" value="New User"
<?php if(!empty($myvals))if(in_array("New User",$myvals))
{echo 'checked="checked"';} ?> />New User <br>
<input type="checkbox" id="chk[]" name="chk[]" value="User Management"
<?php if(!empty($myvals))if(in_array("User Management",$myvals))
{echo 'checked="checked"';} ?> />User Management
</fieldset>
<fieldset style="float:left;">
<legend>Accounts Management</legend>
<input type="checkbox" id="chk[]" name="chk[]" value="Add Accounts"
<?php if(!empty($myvals))if(in_array("Add Accounts",$myvals))
echo 'checked="checked"' ?> />Add Accounts <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Opening Balance"
<?php if(!empty($myvals))if(in_array("Opening Balance",$myvals))
echo 'checked="checked"' ?> />Opening Balance <br>
<input type="checkbox" id="chk[]" name="chk[]" value="View Ledger"
<?php if(!empty($myvals))if(in_array("View Ledger",$myvals))
echo 'checked="checked"' ?> />View Ledger
</fieldset>
<fieldset style="float:left;">
<legend>Inventory Management</legend>
<input type="checkbox" id="chk[]" name="chk[]" value="Unit of Measure"
<?php if(!empty($myvals))if(in_array("Unit of Measure",$myvals))
echo 'checked="checked"' ?>/>Unit of Measure <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Compound UOM"
<?php if(!empty($myvals))if(in_array("Compound UOM",$myvals))
echo 'checked="checked"' ?>/>Compound UOM <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Products"
<?php if(!empty($myvals))if(in_array("Products",$myvals))
echo 'checked="checked"' ?> />Products <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Purchase"
<?php if(!empty($myvals))if(in_array("Purchase",$myvals))
echo 'checked="checked"' ?> />Purchase <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Modify Purchase"
<?php if(!empty($myvals))if(in_array("Modify Purchase",$myvals))
echo 'checked="checked"' ?>/>Modify Purchase <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Sales"
<?php if(!empty($myvals))if(in_array("Sales",$myvals))
echo 'checked="checked"' ?> />Sales <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Modify Sale"
<?php if(!empty($myvals))if(in_array("Modify Sale",$myvals))
echo 'checked="checked"' ?> />Modify Sale
</fieldset>
<fieldset style="float:left;">
<legend>Voucher Management</legend>
<input type="checkbox" id="chk[]" name="chk[]" value="Cash Receipt"
<?php if(!empty($myvals))if(in_array("Cash Receipt",$myvals))
echo 'checked="checked"' ?> />Cash Receipt <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Cash Payment"
<?php if(!empty($myvals))if(in_array("Cash Payment",$myvals))
echo 'checked="checked"' ?>/>Cash Payment <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Bank Receipt"
<?php if(!empty($myvals))if(in_array("Bank Receipt",$myvals))
echo 'checked="checked"' ?>/>Bank Receipt <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Bank Payment"
<?php if(!empty($myvals))if(in_array("Bank Payment",$myvals))
echo 'checked="checked"' ?>/>Bank Payment <br>
<input type="checkbox" id="chk[]" name="chk[]" value="JVs"
<?php if(!empty($myvals))if(in_array("JVs",$myvals))
echo 'checked="checked"' ?> />JVs <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Modify JVs"
<?php if(!empty($myvals))if(in_array("Modify JVs",$myvals))
echo 'checked="checked"' ?> />Modify JVs
</fieldset>
<fieldset style="float:left;">
<legend>Cheque Management</legend>
<input type="checkbox" id="chk[]" name="chk[]" value="Cheque Receipt"
<?php if(!empty($myvals))if(in_array("Cheque Receipt",$myvals))
echo 'checked="checked"' ?> />Cheque Receipt <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Cheque Payment"
<?php if(!empty($myvals))if(in_array("Cheque Payment",$myvals))
echo 'checked="checked"' ?>/>Cheque Payment <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Cheque Return To"
<?php if(!empty($myvals))if(in_array("Cheque Return To",$myvals))
echo 'checked="checked"' ?> />Cheque Return To <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Cheque Return From"
<?php if(!empty($myvals))if(in_array("Cheque Return From",$myvals))
echo 'checked="checked"' ?>/>Cheque Return From <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Cheque Clearance"
<?php if(!empty($myvals))if(in_array("Cheque Clearance",$myvals))
echo 'checked="checked"' ?>/>Cheque Clearance <br>
<input type="checkbox" id="chk[]" name="chk[]" value="Modify Clearance"
<?php if(!empty($myvals))if(in_array("Modify Clearance",$myvals))
echo 'checked="checked"' ?>/>Modify Clearance
</fieldset>
<fieldset style="float:left">
<legend>Reports</legend>
</fieldset>
<div style=" margin-top:10px; float:left; width:70%;">
<input type="submit" id="btnsubmit" name="submit" value="Submit" class="button" />
<input type="button" id="btncheckall" name "btncheckall" value="Check All" class="button"
onClick="selectAll()" />
<input type="button" id="btnuncheckall" name "btnuncheckall" value="Uncheck All" class="button"
onClick="unselectAll()" />
</div>
</form>
</div>
<!-- END content div -->
</body>
</html>
Last edited by hafizfarooq; Jun 27th, 2014 at 11:56 PM.
-
Jun 28th, 2014, 03:52 PM
#3
Re: Unable to check the Checkboxes with Database Values
When you solve your problem, be sure to mark your thread as "Resolved". Near the top click "Thread Tools" > "Mark thread as Resolved"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|