how to insert data in multi dimension array into mysql database in php.

Can you show what you have, and how you want it inserted?

It would help if we could take a look at the array.

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


       require 'connection1.php';





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

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



Member Avatar for diafol

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.

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.