jeudi 1 janvier 2015

How to send dynamic value in checkbox

Good morning . i have created one form to admin to create some user with some permission and i am storing those permission in database using HTML check boxes.and that code is bellow



<label class="q" for="q1">Permission:</label><br>
<div style="padding-left:170px;">
<input name="q1[]" type="checkbox" value="1">Student Management<br>
<input name="q1[]" type="checkbox" value="2">Department Management<br>
<input name="q1[]" type="checkbox" value="3">Course Management<br>
<input name="q1[]" type="checkbox" value="4">Transcript Management<br>
<input name="q1[]" type="checkbox" value="5">Qr Code Printing<br>
<input name="q1[]" type="checkbox" value="6">Settings<br>
<input name="q1[]" type="checkbox" value="7">Upload Scaned Certificate<br>
</div>
/*php action page*/
if(isset($_POST['submit']))
{
$q1=implode(',', $_POST['q1']);


$qry="INSERT INTO user (permission)

VALUES (,'$q1')";

}


And the permission is storing successfully ,but the problem is while trying to edit the permission i am not able to store the default value which is all ready stored in database . the code is



/*getting data from data base*/
if ($result) {
while ( $row = mysql_fetch_array($result) ) {
$q1= $row['permission'];
}
}

/* form for edit permission*/
print"<label class=\"q\" for=\"q1\" >Permission:</label><br>";
print"<div style=\"padding-left:170px;\">";

print"<input name=\"q1[]\" type=\"checkbox\" value=\"1\">Student Management<br>";
print"<input name=\"q1[]\" type=\"checkbox\" value=\"2\">Department Management<br>";
print"<input name=\"q1[]\" type=\"checkbox\" value=\"3\">Course Management<br>";
print"<input name=\"q1[]\" type=\"checkbox\" value=\"4\">Transcript Management<br>";
print"<input name=\"q1[]\" type=\"checkbox\" value=\"5\">Qr Code Printing<br>";
print"<input name=\"q1[]\" type=\"checkbox\" value=\"6\">Settings<br>";
print"<input name=\"q1[]\" type=\"checkbox\" value=\"7\">Upload Scaned Certificate<br>";
print"</div>";
print"</li>";


how to set my default database value for check box that one i need to store in database , please give me some hint i am new to Php, thanks in advance





Aucun commentaire:

Enregistrer un commentaire