Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7825291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:55:14+00:00 2026-06-02T08:55:14+00:00

i have created a database called test and create a table called biodata. I

  • 0

i have created a database called “test” and create a table called “biodata”. I have created 3 columns called “Name” “Age” and “Description” into biodata table. Now how to store my array result into each column.

Below is the complete code…

<?php

    $ip = "localhost";
    $username = "root";
    $password = "";
    $dbname = "test";
    $res = mysql_connect($ip,$username,$password);
    if(!$res)
    {
        echo "DB Connection Failed.";
        exit;
    }
    if(!mysql_select_db("test"))
    {
        echo "NOT SELECTED";
        exit;
    }

        $company =  array(
                    'Record1'=>array('Shabbir',26,'Designer'),
                    'Record2'=>array('Burhan',24,'Architecture'),
                    'Record3'=>array('Huzeifa',20,'Accountant'),
                );

        foreach ($company as $employees=>$details){

        echo '<strong>'.$employees.'</strong><br>';

        foreach($details as $employeeinfo){

            echo $employeeinfo.'<br>';

        }

        }

        $sql = "INSERT INTO biodata (Name, Age, Description) VALUES ($employeeinfo[0], $employeeinfo[1], '$employeeinfo[2]')";
        mysql_query($sql);

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:55:23+00:00Added an answer on June 2, 2026 at 8:55 am

    Your mysql_query is suppose to be inside your foreach statement … you also need to sanitize your data because of SQL Injection

    you also don’t need 2 foreach statement …

    Correction

    foreach ($company as $employees =>$details){
        echo '<strong>'.$employees.' - OK</strong><br>';
        mysql_query(sprintf($sql,mysql_real_escape_string($details[0]),mysql_real_escape_string($details[1]),mysql_real_escape_string($details[2])));
    }
    

    Full Script Arrangement

    $ip = "localhost";
    $username = "root";
    $password = "";
    $dbname = "test";
    $res = mysql_connect($ip,$username,$password);
    $sql = "INSERT INTO biodata (Name, Age, Description) VALUES ('%s', '%d', '%s')";
    $company =  array(
            'Record1'=>array('Shabbir',26,'Designer'),
            'Record2'=>array('Burhan',24,'Architecture'),
            'Record3'=>array('Huzeifa',20,'Accountant'),
    );
    
    if(!$res)
    {
        echo "DB Connection Failed.";
        exit;
    }
    
    if(!mysql_select_db("test"))
    {
        echo "NOT SELECTED";
        exit;
    }
    
    foreach ($company as $employees =>$details){
        echo '<strong>'.$employees.' - OK</strong><br>';
        mysql_query(sprintf($sql,mysql_real_escape_string($details[0]),mysql_real_escape_string($details[1]),mysql_real_escape_string($details[2])));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database called ADB. When I create a new user/role, that user
I have created my database, and used cake bake my_project to create my project,
I have a database created by: -- Database: adatabase -- DROP DATABASE adatabase; CREATE
I have created a table on an Oracle 10g database with this structure :
I have created one user named tuser with create database rights in SQL server
Learning php! I have a sql database which contains a table called 'images' which
I have created an application which inserts data into a SQL database. Basically, from
Say I have already created an iterator called iter and an arraylist called database.
I'm messing around with PHP and a test MYSQL database. I've created a table
I have created a MySQL database using MySQL Workbench. It has about 20 tables.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.