-4

I had successfully pulled out students details that is name , class , section .. as it is a attendance management system. But i facing problem in saving all the values ie Name , Class, Section , Status (P/A) in my database. Bellow the attendance submit code ... please guide me. // showing values

<input type="hidden" id="" name="locationID[]"/><?=$i;?></div></input>
<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);
}
?>

After running this code i am getting Array, in all columns ... please guide me...

  • 5
    Please use a proper title for your question. Also, remove that `@` in front of `session_start` - if it fails you are doing something wrong. Also read about SQL injection. Your code is pretty vulnerable! – ThiefMaster Sep 14 '14 at 09:03
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Sep 14 '14 at 09:06

1 Answers1

0

Assuming that you are return arrays of values in POST, a possible solution could be

$sql = "INSERT INTO tbl_attendence (fld_studentname,fld_status,fld_class,fld_section,fld_date,fld_takenby)
            VALUES ('{$name[$i]}','{$status[$i]}','{$class[$i]}','{$section[$i]}','{$date[$i]}','{$sessionName[$i]}')";

Suggestions: 1. Avoid your code from SQL Injection 2. Use XDebug or use print_r() whenever you see this kind of problem of Array instead of values to debug properly what is the problem.

DJ'
  • 1,737
  • 1
  • 13
  • 26