Hi i am developing Attendence mgt sys. and i have to insert name,section,class,status in database of n number of students. I am able to do listing by the code below:
<?php
@session_start();
include('config.php');
$sessionName = $_SESSION['NAME'];
$sessionID = $_SESSION['UID'];
if($sessionName == "" && $sessionID == "")
{
header('location:index.php');
}
$class = $_REQUEST['class'];
$section = $_REQUEST['section'];
$_SESSION['class'] = $class;
$_SESSION['section'] = $section;
/*This is by me*/
$infoArr = array();
$sql = "SELECT tbl_name,tbl_gender,tbl_class,tbl_section FROM tbl_student_record WHERE tbl_class = '$class' AND tbl_section = '$section'";
$res = mysql_query($sql);
if(mysql_affected_rows() > 0){
$i=0;
while($row = mysql_fetch_array($res)){
$infoArr[$i]['name'] = $row['tbl_name'];
$infoArr[$i]['gender'] = $row['tbl_gender'];
$infoArr[$i]['class'] = $row['tbl_class'];
$infoArr[$i]['section'] = $row['tbl_section'];
$i++;
}
}
$count = count($infoArr);
$newCount = $count - 1;
?>
// HTML
<form action="submitAttendence.php" method="post"/>
<input name="cnt" id="cnt" type="hidden" value="<?=$newCount;?>"/>
<div>
<div class="li-label" style="width:50px;">S.No.</div>
<div class="sep"></div>
<div class="li-label" style="width:250px;">Name</div>
<div class="sep"></div>
<div class="li-label" style="width:100px;">Student ID</div>
<div class="sep"></div>
<div class="li-label" style="width:50px;">Class</div>
<div class="sep"></div>
<div class="li-label" style="width:80px;">Section</div>
<div class="sep"></div>
<div class="li-label" style="width:100px;">Gender</div>
<div class="sep"></div>
<div class="li-label" style="width:100px;">Status</div>
</div>
<div class="cBoth"></div>
<?php
if($newCount > 0){
for($i=0; $i<=$newCount; $i++){
$name = $infoArr[$i]['name'];
$gender = $infoArr[$i]['gender'];
$class = $infoArr[$i]['class'];
$section = $infoArr[$i]['section'];
?>
<div class="vLine"></div>
<div>
<div class="li-txt" style="width:50px;"><?=$i;?></div>
<div class="sep"></div>
<div class="li-txt" style="width:250px;"><input type="hidden" id="name_<?=$i;?>" name="name_<?=$i;?>"/><?=$name;?></div>
<div class="sep"></div>
<div class="li-label" style="width:100px;"><input type="hidden" id="stud_<?=$i;?>" name="stud_<?=$i?>"/>Student ID</div>
<div class="sep"></div>
<div class="li-label" style="width:50px;"><input type="hidden" id="clas_<?=$i?>" name="clas_<?=$i;?>"/><?=$class;?></div>
<div class="sep"></div>
<div class="li-label" style="width:80px;"><input type="hidden" id="sec_<?=$i?>" name="sec_<?=$i?>"/><?=$section;?></div>
<div class="sep"></div>
<div class="li-txt" style="width:100px;"><input type="hidden" id="gen_<?=$i;?>" name="gen_<?=$i?>"/><?=$gender;?></div>
<div class="sep"></div>
<div class="li-txt" style="width:100px;">
<select id="status_<?=$i;?>" name="status_<?=$i;?>"/>
<option value="Present" />Present</option>
<option value="Absent" />Absent</option>
</select>
</div>
</div>
<div class="cBoth"></div>
<?php
}
}
?>
// submitAttendence.php
<?php
include('config.php');
@session_start();
if(isset($_REQUEST['cnt']) && $_REQUEST['cnt'] > 0){
$newCount = $_REQUEST['cnt'];
//echo $newCount; exit;
for($i=0; $i<=$newCount; $i++){
$name = "name_".$i;
echo $name; exit;
$nameVal = $_REQUEST[$name];
$stud = "stud_".$i;
$studVal = $_REQUEST[$stud];
$clas = "clas_".$i;
$clasVal = $_REQUEST[$clas];
$ins = "INSERT INTO tbl_attendence(fld_studentname, fld_class) VALUES('$nameVal', '$clasVal')";
//echo $ins; exit;
mysql_query($ins);
}
}
?>
I am not getting any error but i am not geting any value in my table. Please guide me , i highly appreciate your response.