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 "

"; } ?>

Recommended Answers

All 4 Replies

Member Avatar for Avenirer

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?

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/>";

:( those new auto code-tages are not working

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.