0
   can anyone take alook at my code, i dont get errors or anything but it doesnt save in my db??? please ... thanks!

   <?php

        if(isset($_POST[save]))
        {
            //student,grade,section,subject
            $ids=$_POST['id'];
            $grades=$_POST['fg'];
            $secs=$_POST['secs'];
            $subs=$_POST['subs'];
            $yirs=$g_year['acad_id'];


        debug($_POST);
        if(isset($_POST['save']))
        {

        unset($_POST['save']);
        $i = count($_POST['id']); $x = 0;

            for($x=0; $x <$i;$x++){
            foreach($_POST as $data =>$d){
            echo $data.'-'.$d[$x].'<br/>';

            $num_entry=count($d);

            $insert="INSERT INTO tbl_firstgrading {$data} VALUES (";
            for($i=0;$i<$num_entry;$i++){
            if($i!=$num_entry){
            $insert.="$d,";
            }
            else
            {
            $result=mysql_query($insert)or die(mysql_error());
            }
            }
    //sql statement here (example): insert into table name (value ng $data) values( value ng $d[$x]) -- 
}}}}    

?>
<?php function debug($arr){ echo "

";
                print_r($arr);
                echo "

"; } ?>

4
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by pzuurveen
0

First of all, you have too many if(isset($_POST['save'])) conditions. Second, how did you store multiple id's in the form? Thirdly... what is this? "foreach($_POST as $data =>$d)"? By the way... no filtering?

0
for($i=0;$i<$num_entry;$i++)
                    {
                    if($i!=$num_entry)
                        {
                        $insert.="$d,";
                        }
                    else
                        {
                        // will never run because for-loop exits at same value
                        $result=mysql_query($insert)or die(mysql_error());
                        }
                    }
           // $insert still not finist here see:
           echo "<br/>$insert<br/>";

Edited by pzuurveen: code tage?

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.