Insert Array Data into Mysql Database PHP
Inserting array type data into mysql database table using php programming language is very important thing to learn for all php programmers. It is mostly used in very big applications to develop web pages. You can insert multiple arrays or a single array field with some other fields. Foreach loop will be used to insert array type data into database by using php.
Table of Content
1- Create HTML Form
2- MySQL Database Create a Table
3- PHP Code to Insert Array Data
1- Create HTML Form
First step is to create a new php file within this file write html code and create html form.Within this html form you have to write array input fields. Array input fields in html are written by adding [] braces with name attribute value and same name in each input field of array type. for example name="question[]".
HTML FORM Code Example
Insert Array Data
2- MySQL Database Create a Table
Open phpmyadmin in new tab of browser. Select an existing database or create new database. Within this database create a table in which you want to insert array type data.
3- PHP Code to Insert Array Data
Here you have to write php code of button click you can write this code within same page or write code in a separate file then include this file. Initialize all variables then start a foreach loop for array field variable. Within this foreach loop write insert query of mysql to insert data into database table.
PHP code to insert array type data
';
} else {
$output='Form submitted successfully
Failed to submit form
';
}
}
? >
No comments:
Post a Comment