Example for checkbox with commands INSERT and UPDATE in Php

                    Single page project related to checkbox with commands INSERT and UPDATE.

                   Actually this page was taken from my already done a top SCHOOL management project. The basic idea behind this is as follows:-

1. Storing all the data in a remote server not in local server means maintaining the data in an online database so that admin can use the data from anywhere from his location.


2. At the time when student come to pay the fee the cashier not to enter the fee amount. The term amount generated automatically when cashier select the class and also at each time cashier select the term's checkbox the respective term amount should be displayed in a text box called Total Amount, Obviously the print also come at the time of submit.

Note:-
Here what fee amount decided by admin in his panel per class that amount should be generated.

3. In the same procedure the new student admission also be done.

4. Database should be maintained for each student’s for his marks, admission details, fee and so on...

5. The necessary steps related for a perfect SCHOOL management system.

Meanwhile here I am concentrate on Single page project related for checkbox Using commands INSERT and UPDATE for a student's fee paying page. Actually it contains two pages why because in one page the cashier enters the admission no and select the class and press the submit button, In page2 the respective data automatically generated, Briefly as follows:-

Step1:-
Here cashier simply enters the admission no and select the class and then press submit button.
Note:-
Observe in this page that I am used session so that this page data can easily navigate to another page.

<!--step1 -->
<? session_start();
$cla=$_POST['class'];//here class stores in variable
$cad=$_POST['addno'];
$username=$_POST['uid'];
if(!isset($_SESSION['uid']))
{
echo "<script> location.replace('../index.php'); </script>";
}
?>
<?
if($_POST['submit']=="Enter")
{

$_SESSION['ha']=$cla;//session contains the value class

$_SESSION['ad']=$cad;


$_SESSION['na']=$fel['name'];
echo "<script> location.replace('student_feepaymentbilling.php'); </script>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>cashier</title>
<script language="javascript" src="../js/gen_validatorv31.js"></script>
<link href="cashierstyle.css" rel="stylesheet" type="text/css"/></head>

<body bgcolor="#333333" leftmargin="0" rightmargin="0">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="39" valign="top" align="right"><table width="100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="45"><span class="style3"><a href="billing_joining.php">Home</a></span></td>
<td width="45"><a href="../logout.php"><strong>Logout</strong></a></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" bgcolor="#282828" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><? include "navi.php";?></td>
</tr>
</table></td>
</tr>
<tr>
<td height="313">
<form name="fff" action="" method="post"><table width="286" border="0" align="center">
<tr>
<td colspan="3" ><span class="style12">Student Fee: </span></td>
</tr>
<tr bgcolor="#282828">
<td width="98"><span class="style2 style11">Admission No. </span></td>

<td width="174"><input type="text" name="addno" /></td>
</tr>
<tr bgcolor="#282828">
<td class="style11">Class</td>

<td><table width="86%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="59%"><select name="class">
<option></option>
<option value="lkg">lkg</option>
<option value="ukg">ukg</option>
<option value="class1">class1</option>
<option value="class2">class2</option>
<option value="class3">class3</option>
<option value="class4">class4</option>
<option value="class5">class5</option>
<option value="class6">class6</option>
<option value="class7">class7</option>
<option value="class8">class8</option>
<option value="class9">class9</option>
<option value="class10">class10</option>
</select></td>
<td width="41%">
<div align="right">
<input type="submit" name="submit" value="Enter" />
</div></td>
</tr>
</table></td>
</tr>
</table>
</form>
<script language="JavaScript" type="text/javascript">
var frmvalidator = new Validator("fff");

frmvalidator.addValidation("addno","req","Please Enter Admission No. Number");
frmvalidator.addValidation("addno","numeric");
frmvalidator.addValidation("class","req","Please Select The Class");

</script>

</td>
</tr>
</table>
</body>
</html>

Step2:-
Here cashier just simply click the terms (checkboxes), remaining data will be generated automatically w.r.t to Step1, As you see below figure after the code the date is the current date of the day, the receipt no., the name, class of the student, admission no, finally total of checkbox at each time you select the checkbox.
<!--step2 -->
<?php
session_start();
$username=$_POST['uid'];
$hl=$_POST['class'];
$h2=$_POST['addno'];

$sel=$_SESSION['ha'];
$adm=$_SESSION['ad'];
include "dbconnection.php";
extract($_POST);
$result33=mysql_query("SELECT *
FROM `$sel`
WHERE `addmissionno` = '$adm'
LIMIT 1
");
$fel33=mysql_fetch_array($result33);
if($fel33=="")
{
echo "<script> location.replace('fee_enterclass.php'); </script>";

}

if(!isset($_SESSION['uid']))
{
echo "<script> location.replace('../index.php'); </script>";
}
$result6=mysql_query("SELECT * from feerv where class='$sel'");
$fet6=mysql_fetch_array($result6);

$result=mysql_query("SELECT receipt_no from feebilling ORDER BY receipt_no DESC LIMIT 1 \n");
$fet=mysql_fetch_array($result);
extract($_POST);
if($_POST['submit']=='pay')
{
mysql_query("INSERT INTO feebilling VALUES(`receipt_no`,'$date','$addmission_no','$name','$class','$installment_1','$installment_2','$installment_3','$installment_4')");
$result1=mysql_query("SELECT installment_1,installment_2,installment_3,installment_4 from $class where addmissionno='$addmission_no'");
$fet1=mysql_fetch_array($result1);
$t1=$fet1['installment_1'];
$t2=$fet1['installment_2'];
$t3=$fet1['installment_3'];
$t4=$fet1['installment_4'];

$result2=mysql_query("SELECT installment_1,installment_2,installment_3,installment_4 from feebilling ORDER BY receipt_no DESC LIMIT 1 \n");
$fet2=mysql_fetch_array($result2);
$r1=$fet2['installment_1'];
$r2=$fet2['installment_2'];
$r3=$fet2['installment_3'];
$r4=$fet2['installment_4'];

if($t1 >= $r1)
{
$f1=$t1;
}
else
{$f1=$r1;}

if($t2 >= $r2)
{
$f2=$t2;
}
else
{$f2=$r2;}

if($t3 >= $r3)
{
$f3=$t3;
}
else
{$f3=$r3;}

if($t4 >= $r4)
{
$f4=$t4;
}
else
{$f4=$r4; }

mysql_query("UPDATE `school`.`$class` SET `installment_1` = '$f1',
`installment_2` = '$f2',
`installment_3` = '$f3',
`installment_4` = '$f4' WHERE `$class`.`addmissionno` ='$addmission_no'");

echo "<script> location.replace('fee_receipt.php'); </script>" ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>cashier</title>
<script>
function validate_checkbox ( )
{
valid = true;

if ( document.f1.installment_1.checked == false && document.f1.installment_2.checked == false && document.f1.installment_3.checked == false && document.f1.installment_4.checked == false )
{
alert ( "Please check one of the term" );
valid = false;
}

return valid;
}</script>
<script language=javascript>
var a=10; //set the value of first textbox.
var b=20; //set the value of second textbox.
var c=30; //set the value of third textbox.
function app()
{
if(f1.installment_1.checked==true)
$x=<? echo $fet6['term1']; ?>;
else
$x=0;
if(f1.installment_2.checked==true)
$y=<? echo $fet6['term2']; ?>;
else
$y=0;
if(f1.installment_3.checked==true)
$z=<? echo $fet6['term3']; ?>;
else
$z=0;
if(f1.installment_4.checked==true)
$a=<? echo $fet6['term4']; ?>;
else
$a=0;
if(f1.installment_1.checked || f1.installment_2.checked || f1.installment_3.checked || f1.installment_4.checked==true)
{

$sum=$x+$y+$z+$a;
f1.amt.value=$sum;
}
else
f1.amt.value=0;
}
</script>

<!--Script by hscripts.com-->
</head>
<link href="cashierstyle.css" rel="stylesheet" type="text/css"/>

<body bgcolor="#333333"><form name="f1" action="" onSubmit="return validate_checkbox()" method="post">
<table width="966" border="0">
<tr>
<td height="51" align="right" valign="top">
<table width="100" border="0" cellpadding="1" cellspacing="4">
<tr>
<td width="45"><span class="style1"><strong><a href="billing_joining.php">Home</a></strong></span></td>
<td width="45"><a href="../logout.php"><strong>Logout</strong></a></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="450" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td colspan="4" ><span class="style12">Student Fee Billing:</span></td>
</tr>
<tr bgcolor="#282828">
<td width="77"><span class="style11">Recipt No.</span></td>

<td width="144"><span class="style11"><? echo $fet['receipt_no']+1; ?></span></td>
<td width="91">&nbsp;</td>
<td width="74">&nbsp;</td>
</tr>
<tr bgcolor="#282828">
<td><span class="style11">Date </span></td>

<td><input name="date" type="text" size="8" value="<?php
echo date("Y-m-d");
?>" readonly="readonly"/></td>
<td><span class="style11">Admission No.</span></td>
<td><input name="addmission_no" type="text" size="10" value="<?php
echo $adm;
?>" readonly="readonly"/></td>
</tr>
<tr bgcolor="#282828">
<td><span class="style11">Name</span></td>

<td><input type="text" name="name" value="<? echo $fel33['name']; ?>" readonly="readonly"/></td>
<td><span class="style11">Class</span></td>
<td><input name="class" type="text" size="10" value="<?php
echo $sel;
?>" readonly="readonly"/></td>
</tr>

<tr bgcolor="#282828">
<td class="style11">Payment For </td>

<td><label>
<input type="checkbox" name="installment_1" value="<? echo $fet6['term1']; ?>" onclick="app()"/>
<span class="style11">Term_1</span></label></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#282828">
<td>&nbsp;</td>

<td><input name="installment_2" type="checkbox" value="<? echo $fet6['term2']; ?>" onclick="app()"/>
<span class="style11">Term_2</span></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#282828">
<td>&nbsp;</td>

<td><input type="checkbox" name="installment_3" value="<? echo $fet6['term3']; ?>" onclick="app()"/>
<span class="style11">Term_3</span></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#282828">
<td>&nbsp;</td>

<td><input type="checkbox" name="installment_4" value="<? echo $fet6['term4']; ?>" onclick="app()"/>
<span class="style11">Term_4</span></td>
<td><span class="style11">Total Amount</span></td>
<td><input name="amt" type="text" size="10" readonly="readonly" /></td>
</tr>
<tr>
<td>&nbsp;</td>

<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right"><input type="submit" name="submit" value="pay" /></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>

Output:- For Step1 And Step2



No comments: