4
Contributors
4
Replies
24
Views
4 Years
Discussion Span
Last Post by diafol
0

this is what I have done so far.I'm little bit new to this suff.please help...

    <?php

       require 'connection1.php';

     if(isset($_POST['btnsub'])){

        $num=$_POST['txtnum'];
        $name=$_POST['txtname'];
        $age=$_POST['txtage'];

        $stu=array(

            0=>array('number'=>$num,'name'=>$name,'age'=>$age),
            1=>array('number'=>$num,'name'=>$name,'age'=>$age),
            2=>array('number'=>$num,'name'=>$name,'age'=>$age),
        );

        foreach( $stu as $key =>$info){

            $in="INSERT INTO $tbl ('number','name','age') VALUES ('$key','$info[number]','$info[name]','$info[age]')";

        }

     }



    ?>
0

THat won't work - as you probably know. WHy are you using a repeat of the data into a multidimensional array? THe loop won't work as you expect either. If you have a Primary Key field, just ignore this in the SQL - so no need for a $key - anyway you have different number of fields and values, so it'll throw an error. Also you need to sanitize your input (post) variables before using this type of query. If you use a bound, parameterized query (mysqli or PDO), then it's OK.

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.