Today in this post, we will see how we can Store data to mysql server from MIT App Inventor using php. It is very important because after getting the knowledge the process of Store data to mysql server from MIT App Inventor using php, we can implement it in various project like register and login system, storing record and lots more.

To Store data to mysql server from MIT App Inventor using php, I made a simple project making a Android app of registration form using MIT App Inventor. So for completing the project we need

  1. We have to build mysql database for specific field in registration form.
  2. We have to write php code to collect the data form app and store it to mysql database.
  3. We have to design a registration form on MIT App Inventor.
  4. We have to give proper logical block connection for registration form on MIT App Inventor.
  5. Hosted domain.

Building mysql database:

For building a mysql database in any hosted domain. Go to their control panel and enter into phpMyAdmin. After entering inside phpMyAdmin we can able to see the name of database at left hand side menu bar.

Store data to mysql server from MIT App Inventor using php

Now to Store data to mysql server from MIT App Inventor using php, we need a table with same field as in registration form. To create a new table in database we have to give a table name and number of field required and we have to press go button.

After creating database now we have to enter the details of field like field name, length, type, attribute etc.

Store data to mysql server from MIT App Inventor using php

Now you can also use lots of free web hosting service provider with frre sub domin to work with your project. Please see the bellow video to get full process of making a mysql database.

PHP code to collect the data form app:

In above section we learn making a mysql database in web server. Now to complete the project Store data to mysql server from MIT App Inventor using php, our next step will be writing PHP code to collect the data form app. In bellow I give complete PHP code for table nbcafe with above fields shown in above picture.

<?php
define (‘dbuser’,’your db user’);
define (‘dbpw’,’your db password’);
define (‘dbhost’,’your db host’);
define (‘dbname’,’your db name’);
$dbc = mysqli_connect(“your db host”, “your db user”, “your db password”, “your db name”);
if(!$dbc) {
die(“DATABASE CONNECTION FAILED:” .mysqli_error($dbc));
exit();
}
$dbs = mysqli_select_db($dbc, dbname);
if(!$dbs) {
die(“DATABASE SELECTION FAILED:” .mysqli_error($dbc));
exit();
}
$firstname = mysqli_real_escape_string($dbc, $_GET[‘firstname’]);
$lastname = mysqli_real_escape_string($dbc, $_GET[‘lastname’]);
$fathername = mysqli_real_escape_string($dbc, $_GET[‘fathername’]);
$mobile = mysqli_real_escape_string($dbc, $_GET[‘mobile’]);
$dob = mysqli_real_escape_string($dbc, $_GET[‘dob’]);
$class = mysqli_real_escape_string($dbc, $_GET[‘class’]);
$school = mysqli_real_escape_string($dbc, $_GET[‘school’]);
$email = mysqli_real_escape_string($dbc, $_GET[’email’]);
$address = mysqli_real_escape_string($dbc, $_GET[‘address’]);
$user_id = mysqli_real_escape_string($dbc, $_GET[‘user_id’]);
$psw = mysqli_real_escape_string($dbc, $_GET[‘psw’]);
$query = “INSERT INTO nbcafe (first_name, mobile_number, date_of_birth, class, school_name, email, user_id, psw) VALUES (‘$firstname’, ‘$mobile’, ‘$dob’, ‘$class’, ‘$school’, ‘$email’, ‘$user_id’, ‘$psw’)”;
if(mysqli_query($dbc, $query)){
echo “Records added successfully.”;
} else{
echo “ERROR: Could not able to execute $query. ” . mysqli_error($dbc);
}
mysqli_close($dbc);
?>

Design a registration form on MIT App Inventor

To design a registration form on MIT APP Inventor I used eight label to write our eight filed name. Seven text field box to take text input. One password text box to take password. And one button to make register button. For working with programming logic we have to take Non-Visible component Web1 and Notifier1.

Store data to mysql server from MIT App Inventor using php

Logical block connection for registration form :

The main portion of this project is proper logical block connection for registration form. The main aim of this app is take the input data and send it to PHP by making exact url.

  1. So first work of our app will be making url with user data.

Store data to mysql server from MIT App Inventor using php

  1. After sending proper url to PHP, Second work has to get the server response. In me PHP I write if data added successfully it show massage “Records added successfully.” If any problem arrived it show massage “ERROR: Could not able to execute”. So for that we have to definitely add some logic box.

Store data to mysql server from MIT App Inventor using php

So in this way we can easily Store data to mysql server from MIT App Inventor using php.

The complete video with step by step process shown below.