<input type="hidden" id="" name="name[<?=$name;?>]"/><?=$name;?></input>
....

<?php
include('config.php');
@session_start();
$sessionName = $_SESSION['NAME'];
$date = date('d-m-y');
$loc= $_POST['locationID'];
$name = $_REQUEST['name'];
$status = $_POST['status'];
$class = $_POST['class'];
$section = $_POST['section'];
for( $i = 0; $i < count($loc); $i++ )
{

    $sql = "INSERT INTO tbl_attendence (fld_studentname,fld_status,fld_class,fld_section,fld_date,fld_takenby)

        VALUES
        ('$name','$status','$class','$section','$date','$sessionName')

        ";
        //echo $sql; exit;

      mysql_query($sql);

}
?>

Recommended Answers

All 9 Replies

I m fetching some values from database , like this
<input type="hidden" id="" name="name[]"/><?=$name;?></input>
<input type="hidden" id="" name="class[]"/><?=$class;?></input>
<input type="hidden" id="" name="section[]"/><?=$section;?></input>
<input type="hidden" id="" name="status[]"/><?=$status;?></input>

And above is the php code which i am uing to insert these values, i am not getting any error but results are in not my favour, i am getting "Array","Array","Array" multiple times as per the loop.

please guide me , i appreciate your response, i am new in this domain.

Member Avatar for diafol

Do not use $_REQUEST. Why are you using this?
Do not run multiple INSERT queries. Build up a VALUES clause in your loop and run a single INSERT query.
Do not use mysql_* functions they have been deprecated - use PDO or mysqli.
Do not have id="" - if you're not using it, why have it?

Why have you got hidden input fields? These are often used due to poor logic. Are you sure that they're required?

so what i have to do? please guide me

how to build a value clause? Please guide me.

$sessionName = $_SESSION['NAME'];
$date = date('d-m-y');
$loc= $_POST['locationID'];
$name = $_REQUEST['name'];
$status = $_POST['status'];
$class = $_POST['class'];
$section = $_POST['section'];

$i = 0;
while($i<count($loc)){

  $session = mysql_real_escape_string($sessionName[$i]);
   $fdate = mysql_real_escape_string($date[$i]);
    $location = mysql_real_escape_string($loc[$i]);

     $sts = mysql_real_escape_string($status[$i]);
    $cls = mysql_real_escape_string($class[$i]);
    $sec = mysql_real_escape_string($section[$i]);

    $query = "INSERT INTO `tbl_attendence` ( 
       `fld_studentname`, `fld_status`, `fld_class`, `fld_section`, `fld_date`, `fld_takenby`
        ) VALUES (
         '$session',
        '$sts',
        '$cls',
        '$sec',
        '$fdate',
        '$name'
            )
        "; 

    mysql_query($query);          
    $i++;  
}

if(mysql_affected_rows()>0){
    echo "Attendance Updated Successfully";
} else {
    echo "There was an error updating attendance.please contact with server admin or try again";
    echo "<br><br>Error: " . mysql_error();
    echo "<br><br>Query: " . $query;
} 

here i assume $name is for fld_takenby ,i will appreciate if you please let me know the result.

Member Avatar for diafol

Can't really help until you answer pritaeas' question. You may wish to implement a few of my suggestions. Then we can look at the loop/values.

hi maruf22,

i am getting no values, however in $status , it is saving P,r,e as loop is running three time. Please help me Maruf..

<?php
include('config.php');
@session_start();
@$sessionName = $_SESSION['NAME'];
$date = date('d-m-y');
$loc = $_POST['locationID'];
@$name = $_POST['name'];
$status = $_POST['status'];
$class = $_POST['class'];
$section = $_POST['section'];
$i = 0;
while($i<count($loc)){
        $fname = mysql_real_escape_string($name[$i]);
        $sts = mysql_real_escape_string($status[$i]);
        $cls = mysql_real_escape_string($class[$i]);
        $sec = mysql_real_escape_string($section[$i]);
    $query = "INSERT INTO tbl_attendence ( 
       fld_studentname, fld_status, fld_class,fld_section,fld_date,fld_takenby)

        VALUES (
        '$fname',
        '$sts',
        '$cls',
        '$sec',
        '$date',
        '$sessionName'
            )
        "; 
    mysql_query($query);          
    $i++;  
}
if(mysql_affected_rows()>0){
    echo "Attendance Updated Successfully";
} else {
    echo "There was an error updating attendance.please contact with server admin or try again";
    echo "<br><br>Error: " . mysql_error();
    echo "<br><br>Query: " . $query;
} 
?>

Hi Maruff, I am not getting any value it is shwoing blank. Please guide me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.