0

<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);

}
?>
4
Contributors
9
Replies
29
Views
3 Years
Discussion Span
Last Post by zeeshan009
0

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.

0

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?

0

how to build a value clause? Please guide me.

Edited by zeeshan009

-1
$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.

0

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.

-1

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..

-1
<?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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.