React Native Insert Text Input Data To MySQL Server Android iOS Tutorial

How to Insert Text Input Data – store multiple TextInput component entered data to online PHP MySQL database server using Fetch API and Show server response inside app using Alert message after successfully inserted record.

Inserting data from React Native application to MySQL database is a very important task to every developer because without submitting data from app there is no dynamic activity in project. So in this tutorial we would going to create a react native application which would stores the Text Input entered value into MySQL database and after successfully inserting the record it would show us the response conformation message coming from server into Alert message. So let’s get started .


Contents in this project Insert Text Input Data To MySQL Server :

1. Create a database + Table on your online hosting server.

Create a database on your MySQL server, then Create a fresh table inside the database. The table name should be UserInfoTable . Add 4 columns inside the table id, name, email, phone_number .

2. Create PHP script to insert received data from React Native application into MySQL database.

Create 2 PHP files DBConfig.php and submit_user_info.php .

DBConfig.php : This file contains the MySQL database hostname, database name, database password and database username.

submit_user_info.php : This file receive the send record from application and insert that received data into MySQL database.

Code for DBConfig.php file :

Code for submit_user_info.php file :

3. Start a fresh React Native project. If you don’t know how then read my this tutorial.

4. Add AppRegistry, StyleSheet, TextInput, View, Alert, Button component inside the import block.

5. Create constructor.

Create a constructor in your Main Class with props parameter. Now declare three variables TextInputName: ‘ ‘, TextInputEmail: ‘ ‘ and TextInputPhoneNumber: ‘ ‘ with empty values using this.state.

6. Create function named as InsertDataToServer() to send the Text Input data on server.

7. Create custom css class named as MainContainer and TextInputStyleClass just above the AppRegistry.registerComponent line.

8. Add View as parent view in render’s return block and Call the MainContainer class into View.

9. Add 3 Text Input and 1 Button component inside the View .

placeholder = Shows hint inside the Text Input.

onChangeText = Every time when user type anything in Text Input it will store the entered value in state variable.

underlineColorAndroid = Hide the Text Input base line.

style = Used to call css class.

onPress = Call the InsertDataToServer() function on button onPress.

10. Complete source code for index.android.js / index.ios.js file.

Screenshots :
Insert Text Input Data