IBM has open contract positions for Bluemix

IBM has open contract positions for Bluemix in all of ASEAN (SG, MY, TH, ID, PH) for fresh graduates.

IBM Bluemix

IBM Bluemix

Candidate should fit 2-3 of the minimum requirements:
1. Minimum of 2 years in Web Application Development using NodeJS, Java or Go
2. Minimum of 2 years in Android or iOS application development
3. Familiar with Web stack – HTML, CSS and JavaScript.
4. Familiar with MongoDB or other NoSQL (Document-based)
5. Familiar with Relational Database
6. Familiar with Web Services (REST or SOAP) and OOP concept
7. Familiar with cloud environment (IaaS or PaaS)
Bonus points for:
1. Experience or knowledge in data analytics – especially social media analytics
2. Experience in web development framework – Angular JS, jQuery, Bootstrap
3. Skill in other programming language (Ruby, Python, Scala, C#, etc)
4. Conceptual knowledge in MVC or microservices
5. Past experience in using PaaS
6. Experience in IoT related development (Raspberry Pi, Arduino, etc)
7. Degree in Computer Science / Computer Engineer / AI
8. Experience in DevOps – i.e. Continuous Integration, Continuous Deployment is a plus
9. Experience or knowledge in Docker container technology.

To those interested, can send your resume to st.wissel@sg.ibm.com.

AngularJs Ionic Mobile App Development Tutorial – Marketing App – Part 1

In this tutorial you will develop a marketing app for iOS and android with these features

  • Login (Facebook Login)
  • Edit profile
  • Create and view all campaign details
  • View reports

What you will be learn from this tutorial are

  • Setup development environment using certain IDE for iOS and android.
  • Preview your iOS and android hybrid app on actual device (smart phone).
  • Develop iOS and android hybrid app using client side language.
  • Create multi page application for iOS and android hybrid app.
  • Connect iOS and android hybrid app with server side language.

Download the required software packages.

Download and install Eclipse Juno SR2 and Xcode 6 (if you’re using Mac for mobile development).

Eclipse Juno SR2 – http://www.eclipse.org/downloads/packages/release/juno/sr2
Xcode 6 – https://developer.apple.com/xcode/downloads/

Setup ADT and Android SDK into your eclipse.

Then you need to setup cordova using NPM (node package manager).

ADT and Android SDK Setup

Don’t forget to install or update your machine with latest JDK 7. Download at http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html.

After you download, make sure you set the correct java path. If not, you can’t start your eclipse. You can download eclipse Juno http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/junosr2.

Then install it. After you install the tool that I tell you, make sure you install ADT (android development tools).

Go to Help and choose Install New Software.

eclipse - Install New Software

eclipse – Install New Software

Click Add button then popup box will appear. Enter ‘ADT’ in name textfield and ‘https://dl-ssl.google.com/android/eclipse/’ in location textfield.

eclipse - Install ADT

eclipse – Install ADT

Click Select All button and click Next.

eclipse - Install ADT

eclipse – Install ADT

Click Next.

eclipse - Install ADT

eclipse – Install ADT

Select I accept the terms of the license of agreement. Click Finish.

eclipse - Install ADT

eclipse – Install ADT

After finished setup ADT in your eclipse, download android SDK (http://developer.android.com/sdk/index.html#Other) and update latest android version or depends on your device for testing. After you install the android SDK, open android SDK , /android-sdk/tools. For this tutorial we will using latest android SDK, Android 5.0 aka Lolipop. Open your terminal/cmd, type android command and enter.

android terminal

android terminal

Select Android 5.0 and click Install 12 packages.

Android SDK Manager

Android SDK Manager

Select all packages, choose Accept License and click Install.

Android SDK Manager

Android SDK Manager

After that, install node.js (http://nodejs.org/) to use npm for package manager. If you not install node.js, you should not be able to invoke node or npm on your command line to install cordova apache. Then install cordova apache using terminal for Mac, command prompt for Windows.

Type this command to install cordova apache.

For Mac

sudo npm install -g cordova ionic

For Windows. If you can’t install, make sure you run the command prompt as administrator.

npm install -g cordova ionic
sudo npm install -g cordova ionic

sudo npm install -g cordova ionic

sudo npm install -g cordova ionic

sudo npm install -g cordova ionic

After you finish install the cordova apache. You can start create your project using cordova command. Open your terminal/command prompt, type these command. You can ignore sudo if you using Windows.

ionic start com.revivalx.cordova.marketing
ionic create project

ionic create project

Open config.xml inside cordova project that you already created just now. Change id and name. Others are optional.

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.revivalx.cordova.marketing" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>ToDo</name>
    <description>
        Marketing App.
    </description>
    <author email="mohammadnrdn@gmail.com" href="http://revivalx.com">
        Mohammad Nurdin bin Norazan
    </author>
    <content src="index.html" />
    <access origin="*" />
</widget>

Go back to terminal and add platform for android/iOS. Type these command to add both platforms.

ionic platform add android
ionic platform add android

ionic platform add android

ionic platform add ios
ionic platform add ios

ionic platform add ios

Note, if you got some error message during add andorid platform, you can refer to this link

Common errors during developing hybrid android app– http://blog.revivalx.com/2014/11/02/common-errors-during-developing-android-hybrid-app/

Android part.

Go to eclipse and import android project. Click File and choose Import.

eclipse - import project

eclipse – import project

Choose Existing Android Code into Workspace and click Next.

eclipse - existing android code into workspace

eclipse – existing android code into workspace

Browse your android project and select all. Click Finish.

eclipse – import projects

eclipse – import projects

Make sure you already connect your mobile device (android phone) and enable USB debugging.

Enable USB debugging: http://www.phonearena.com/news/How-to-enable-USB-debugging-on-Android_id53909

Right click android project > Run As > Android Application.

Run As Android Application

Run As Android Application

Select your phone and click Ok.

Android Device Chooser

Android Device Chooser

If successful, your app shown like this.

cordova app preview on android

ionic app preview on android

iOS part.

Open your cordova project for iOS. Go to../com.revivalx.ionic.marketing/platforms/ios/com.revivalx.ionic.marketing.xcodeproj . Select iPhone6 simulator and click Play button.

xcode6

xcode6

If successful, your app shown like this.

ionic app preview on iOS

ionic app preview on iOS

I think thats all for

  • Setup development environment using certain IDE for iOS and android.
  • Preview your iOS and android hybrid app using emulator and actual device (smart phone).

Next tutorial we will develop iOS and android hybrid app using client side language.

Integration Cordova Facebook Connect Plugin for android

In this tutorial, we will learn how to integrate your app with Cordova Facebook Connect Plugin. This tutorial only cover for iOS and android platform.

Before you proceed this tutorial, make sure you already have pre installed with

in your machine.

To use this plugin you will need to make sure you’ve registered your Facebook app with Facebook and have an APP_ID (https://developers.facebook.com/apps). 

If you plan on rolling this out on iOS, please note that you will need to ensure that you have properly set up your Native iOS App settings on the Facebook App Dashboard. Please see the Getting Started with the Facebook SDK: Create a Facebook App section, for more details on this.

If you plan on rolling this out on Android, please note that you will need to generate a hash of your Android key(s) and submit those to the Developers page on Facebook to get it working.

facebook developer

facebook developer

Firstly you need to register your app on the facebook developer. https://developers.facebook.com/ . Make sure you have facebook account before proceed. Go to Apps tab and select Create a New App.

facebook developer

facebook developer

Enter your display name and select category. Leave it blank for namespace. Then click Create App.

facebook create a new app

facebook create a new app

Enter the captcha text then submit.

facebook captcha

facebook captcha

You will see your facebook app details here. Your App ID will be use for Cordova Facebook Connect Plugin.

facebook developer dashboard

facebook developer dashboard

Go to setting page to setup your ios and android for cordova facebook connect plugin.

facebook developer basic setting

facebook developer basic setting

Click Add Platform and select ios platform.

facebook app select platform

facebook app select platform ios

Enter your bundle ID and enable Single Sign On. Your bundle ID will be com.revivalx.cordova.facebook . And click Save Changes.

facebook ios setting

facebook ios setting

Add platform for android.

facebook app select platform android

facebook app select platform android

Android setting require a hash key. To get this hash key, you need to run this command to generate it. Run this command in your terminal.

keytool -exportcert -alias Cordova Connect Plugin -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
hash key for android

hash key for android

You will get your hash key, RZDg+xMYTX/NZm2BxXIUnATSAf0= . Enter your package name and hash key. Then don’t forget to enable Single Sign On. Click Save Changes to save.

facebook app android basic setting

facebook app android basic setting

You need to create a cordova project using terminal (mac)/ cmd (windows). You need to install node.js to run cordova command. Please refer to this site how to install cordova using NPM. https://www.npmjs.org/package/cordova .

After that, type this command into your terminal.

cordova create com.revivalx.cordova.facebook

Then add platform for iOS and android

cordova platform add android
cordova platform add ios
create project com.revivalx.cordova.facebook

create project com.revivalx.cordova.facebook

Install this cordova facebook connect plugin into your cordova project  using this command.

cordova plugin add https://github.com/phonegap/phonegap-facebook-plugin --variable APP_ID="589003057863589" --variable APP_NAME=“Cordova Connect Plugin”
cordova facebook connect plugin

cordova facebook connect plugin

Open up your eclipse and create a new project. Click File > New > Other.

eclipse new project

eclipse new project

Choose Project under General category and click Next.

eclipse new project

eclipse new project

Enter your project name. We name it for this tutorial, com.revivalx.cordova.facebook . 

Screen Shot 2014-05-17 at 4.43.24 AM

Then choose your location for your project. Click Finish. Your project hierarchy will be like this.

com.revivalx.cordova.facebook

com.revivalx.cordova.facebook

Open up your config.xml and change with this one.

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.revivalx.cordova.facebook" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>CordovaFacebook</name>
    <description>
        This source code provides example for facebook login.
    </description>
    <author email="mohammadnrdn@gmail.com" href="http://revivalx.com">
        Mohammad Nurdin bin Norazan
    </author>
    <content src="index.html" />
    <access origin="*" />
</widget>

example hackbook

example hackbook

Then go to www folder inside plugins folder in your parent folder. com.revivalx.cordova.facebook plugins > com.phonegap.plugins.facebookconnect www . Copy two these files inside your www folder. com.revivalx.cordova.facebook > www.

com.phonegap.plugins.facebookconnect

com.phonegap.plugins.facebookconnect

Open your index.html file in parent folder and replace this code with this one. Copy app id that already generated from facebook developer app website.

// Initialize the Facebook SDK
document.addEventListener('deviceready', function() {
FB.init({
appId: '589003057863589',
nativeInterface: CDV.FB,
useCachedDialogs: false
});
FB.getLoginStatus(handleStatusChange);
authUser();
updateAuthElements();
});

If you want to create an android app, make sure you copy all these files into src folder in your cordova project. These are your ‘Facebook SDK’. You don’t need to download Facebook Android SDK bundle on the Facebook Developer. Download all these files first. https://github.com/phonegap-build/FacebookConnect/tree/master/src/android/facebook .

  • AsyncFacebookRunner.java
  • DialogError.java
  • Facebook.java
  • FacebookError.java
  • FbDialog.java
  • Util.java

Create a hierarchical folder (com.facebook.android) inside src folder. com.revivalx.cordova.facebookplatforms > android > src .

com.facebook.android folder

com.facebook.android folder

Copy all these files into your src folder. com.revivalx.cordova.facebookplatforms > android > src > com > facebook > android

com.facebook.android

com.facebook.android

Replace ConnectPlugin.java file with this one, https://github.com/phonegap-build/FacebookConnect/blob/master/src/android/ConnectPlugin.java .

Cordova Facebook Connect Plugin

Cordova Facebook Connect Plugin

Go to res folder and copy it into android folder.

Build your project for ios and android using terminal.

cordova build ios

cordova build android

Import another project for android and cordova library.

import android project

import android project

Select Existing Android Code Into Workspace under Android category.

import android

import android

 Select All except FacebookLib project. Click Finish.

import android project

import android project

Right click project. Select Run As > Android Application.

Run As Android Application

Run As Android Application

Choose a running Android device and click OK.

android device chooser

android device chooser

Download sample app: https://github.com/datomnurdin/com.revivalx.cordova.facebook

Then your app will running in your device. Next tutorial I will show for iOS part. Don’t hesitate to contact me if you got any questions or problems about this problem.

Create Cordova project from scratch

I always hang around in stackeoverflow, helping another programmers to fix their programming issues. From my observation, a few of them don’t know how to create a cordova project from scratch. I don’t know why it happen because everytime I refresh stackoverflow page that containing cordova tag, they keep asking how to create cordova project.

Even there are a plenty of tutorials in the internet, they still unable to setup their first project. Below is a part of cordova official site how to using CLI AKA Command Line Interface.

http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html

So, I take an action to post this tutorial so we can share to another peoples. Sharing is caring right?Firstly, you need to install node.js into your machine. (remember, I’m using mac machine for development).

http://nodejs.org/

Make sure you update the latest iOS SDK for iOS development. Then download and install android SDK. After that, make sure you set path for android SDK. Mine using mac, so I need to create file called .bash_profile. I created in User directory as you can see here.

.bash_profile

.bash_profile

Edit .bash_profile using this command

export PATH="/Applications/android-sdk/tools:/Applications/android-sdk/platform-tools:$PATH"

I’m installed my android sdk into my application directory.

For windows, I suggest you setup path in environment variable. Right click my computer > Advanced system settings > Advanced > Environment Variables. Use these setting for your ANDROID_HOME path.

Add the platform-tools\ directory to your Windows path:

;C:\Development\Android\android-sdk-windows\platform-tools\</strong>

For Mac user

After that, you need to install ANT using brew. Download and install Homebrew by executing following command in terminal:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Install Apache Ant via Homebrew by executing

brew install ant

For Windows user

Download and install ant for windows.

https://code.google.com/p/winant/downloads/list

Install cordova via NPM. NPM is Node Package manager. Installs, publishes and manages node programs. Run this command in terminal (mac user).

npm install cordova

If you got error regarding to permission issue, you need to run the command using SUDO.

Error: EACCES, permission denied

sudo npm install cordova
npm install cordova

npm install cordova

For windows, the command is similar to mac. If you got trouble with permission issue, run your command prompt as administrator. Right click command prompt > Run as administrator .

Then your cd to your workspace.

Mac

cd /Users/mohammadnurdin/Desktop

Windows

cd C:\Users\m.nurdin\Dekstop

Create your project using cordova command.

cordova create your-project-name

You will see your project structure will be like this.

cordova project

cordova project

cd to your cordova project.

cd your-project-name

Add platform device into your project. You can choose base on your needs.

cordova platform add ios

cordova platform add android

cordova platform add wp8
cordova platform

cordova platform

P.S: For this tutorial I can’t perform for (wp8) windows mobile because I’m using mac. It needs .NET Framework 4.0 to make it works.

Build your project for each platform.

cordova build ios

cordova build android

cordova build wp8

Voila !!!

If you want a sample code for this tutorial, let me know.

CRUD operation using jquery mobile on android – Part 2

This is a second part of 2-part tutorial series on CRUD operation using jquery mobile on android. In the first tutorial, you learned how to setup your android environment, create cordova/phonegap project using eclipse and node.js and how to test your app using android simulator without device.

http://blog.revivalx.com/2014/02/21/crud-operation-using-jquery-mobile-on-android-part-1/

In this second part, you will learn how to create a simple web service for your app. Your web service will enable to create, read, update and data using JSON ( Javascript Object Notation) to your database. We will not using SOAP (Simple Object Access Protocol) for this tutorial because JSON is easy to learn and simple compare to SOAP is too complex for beginner. It basically works on HTTP protocol.

URL Structure

In web service design the URL endpoints should be well formed and should be easily understandable. Every URL for a resource should be uniquely identified.

For example

GET – http://localhost:8888/crud_tutorial/product/index

GET – http://localhost:8888/crud_tutorial/product/display?productId=1

POST – http://localhost:8888/crud_tutorial/product/create

POST – http://localhost:8888/crud_tutorial/product/update?productId=1

POST – http://localhost:8888/crud_tutorial/product/delete?productId=1

Why we using JSON for mobile application? Why not we access directly to our database without using JSON instead PHP or JAVA. It is because hybrid mobile app support client side languages, not servers side languages. Hybrid mobile app consists these 3 languages are HTML5, CSS and Javascript. We can’t simply run PHP or JAVA in mobile app. This video will answer these questions.

Getting started.

For this tutorial you need to have basic in PHP and Mysql. You need to have eclipse Helios to complete the project. Compare to previous tutorial we using eclipse Juno. It is because we develop an android app. For eclipse PHP we develop web service using PHP.

First you need to setup a web server in your machine. I’m using MAMP (stands for Mac, Apache, Mysql and Php) for this tutorial. It’s ok if your want to use other than this such as XAMPP or WAMP. No problem with that. But i suggest you using MAMP if you using Mac. There will be a lot of glitches if you using XAMPP or WAMP in your apple machine.

Download MAMP from this site and install to your machine. After finish installed MAMP to your machine, start apache server and mysql server. So far I didn’t get any issues starting my web server compare to XAMPP. If you got problem start up your apache server, make sure you check port 80 because maybe other applications using the same port especially skype. you need to terminate the application before start the apache server. This issue always happened to windows users.

If your apache and mysql server running successful, you will get like this (green light on both server status).

MAMP

MAMP

Then open your chrome browser. Why I’m using chrome rather than other browser because there are a tons of chrome extensions available in chrome marketplace. That’s why i choose to live with it. Type this to open your MAMP start page in your browser.

http://localhost:8888/MAMP/?language=English

Then click phpMyAdmin at top of the bar. You will see this page.

phpmyadmin

phpmyadmin

You need to create a database and a table for this tutorial. Click database tab. Then create ‘crud_tutorial‘. Copy this sql script to your sql tab to generate product table.

CREATE TABLE `product` (
`productId` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) NOT NULL,
`description` varchar(500) NOT NULL,
`quantity` decimal(10,0) NOT NULL,
`price` decimal(10,0) NOT NULL,
`dateCreated` datetime NOT NULL,
`dateUpdated` datetime NOT NULL,
PRIMARY KEY (`productId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

After executing these queries go through each tables and make sure that everything created correctly. Until now we are done with getting your system ready for development. Run your eclipse Helios to start develop web service. Right click in PHP explore > New > PHP Project.

eclipe helios

eclipe helios

Type crud_tutorial in project name. At content part, choose create project at existing location (from existing source). Type path name in directory field. /Applications/MAMP/htdocs/crud_tutorial  . Click Finish.

create project

create project

Right click in your project, select New > PHP File .

PHP File

PHP File

Type db_config.php and click Finish.

New php file

New php file

You need to create 5 more php files for db_connect.php, create_product.phpget_product_details.php, get_all_products.php, update_product.php and delete_product.php. You can check reference that I take from this site for this tutorial.

db_connect.php – database configuration / setting.

db_connect.php – database connection.

create_product.php – create product details into database.

get_product_details.php – get product details base on product id from database.

get_all_products – retrieve all list of products.

update_product.php – update product into database base on product id.

delete_product.php – delete product from database base on product id.

Fill up all these PHP files using these code.

db_connect.php

<?php
define('DB_USER', "root"); // db user
define('DB_PASSWORD', "root"); // db password (mention your db password here)
define('DB_DATABASE', "crud_tutorial"); // database name
define('DB_SERVER', "localhost"); // db server
?>

db_connect.php

<?php
class DB_CONNECT {
 
    // constructor
    function __construct() {
        // connecting to database
        $this->connect();
    }
 
    // destructor
    function __destruct() {
        // closing db connection
        $this->close();
    }
 
    /**
     * Function to connect with database
     */
    function connect() {
        // import database connection variables
        require_once __DIR__ . '/db_config.php';
 
        // Connecting to mysql database
        $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
 
        // Selecing database
        $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
 
        // returing connection cursor
        return $con;
    }
 
    /**
     * Function to close db connection
     */
    function close() {
        // closing db connection
        mysql_close();
    }
 
}
 
?>

create_product.php

<?php
  
/*
 * Following code will create a new product row
 * All product details are read from HTTP Post Request
 */
  
// array for JSON response
$response = array();
  
// check for required fields
if (isset($_POST['name']) && isset($_POST['description']) && isset($_POST['quantity']) && isset($_POST['price'])) {
  
    $name = $_POST['name'];
    $description = $_POST['description'];
    $quantity = $_POST['quantity'];
    $price = $_POST['price'];
  
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
  
    // connecting to db
    $db = new DB_CONNECT();
  
    // mysql inserting a new row
    $result = mysql_query("INSERT INTO product(name, description, quantity, price, dateCreated, dateUpdated) VALUES('$name', '$description', '$quantity', '$price', NOW(), NOW())");
  
    // check if row inserted or not
    if ($result) {
        // successfully inserted into database
        $response["success"] = 1;
        $response["message"] = "Product successfully created.";
  
        // echoing JSON response
        echo json_encode($response);
    } else {
        // failed to insert row
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";
  
        // echoing JSON response
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
  
    // echoing JSON response
    echo json_encode($response);
}
?>

get_product_details.php

<?php
  
/*
 * Following code will get single product details
 * A product is identified by product id (productId)
 */
  
// array for JSON response
$response = array();
  
// include db connect class
require_once __DIR__ . '/db_connect.php';
  
// connecting to db
$db = new DB_CONNECT();
  
// check for post data
if (isset($_GET["productId"])) {
    $productId = $_GET['productId'];
  
    // get a product from product table
    $result = mysql_query("SELECT *FROM product WHERE productId = $productId");
  
    if (!empty($result)) {
        // check for empty result
        if (mysql_num_rows($result) > 0) {
  
            $result = mysql_fetch_array($result);
  
            $product = array();
            $product["productId"] = $result["productId"];
            $product["name"] = $result["name"];
            $product["description"] = $result["description"];
            $product["price"] = $result["price"];
            $product["price"] = $result["price"];
            $product["dateCreated"] = $result["dateCreated"];
            $product["dateUpdated"] = $result["dateUpdated"];
            // success
            $response["success"] = 1;
  
            // user node
            $response["product"] = array();
  
            array_push($response["product"], $product);
  
            // echoing JSON response
            echo json_encode($response);
        } else {
            // no product found
            $response["success"] = 0;
            $response["message"] = "No product found";
  
            // echo no users JSON
            echo json_encode($response);
        }
    } else {
        // no product found
        $response["success"] = 0;
        $response["message"] = "No product found";
  
        // echo no users JSON
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
  
    // echoing JSON response
    echo json_encode($response);
}
?>

get_all_products.php

<?php
  
/*
 * Following code will list all the products
 */
  
// array for JSON response
$response = array();
  
// include db connect class
require_once __DIR__ . '/db_connect.php';
  
// connecting to db
$db = new DB_CONNECT();
  
// get all products from product table
$result = mysql_query("SELECT *FROM product") or die(mysql_error());
  
// check for empty result
if (mysql_num_rows($result) > 0) {
    // looping through all results
    // products node
    $response["products"] = array();
  
    while ($row = mysql_fetch_array($result)) {
        // temp user array
        $product = array();
        $product["productId"] = $row["productId"];
        $product["name"] = $row["name"];
        $product["description"] = $row["description"];
        $product["quantity"] = $row["quantity"];
        $product["price"] = $row["price"];
        $product["dateCreated"] = $row["dateCreated"];
        $product["dateUpdated"] = $row["dateUpdated"];
  
        // push single product into final response array
        array_push($response["products"], $product);
    }
    // success
    $response["success"] = 1;
  
    // echoing JSON response
    echo json_encode($response);
} else {
    // no products found
    $response["success"] = 0;
    $response["message"] = "No products found";
  
    // echo no users JSON
    echo json_encode($response);
}
?>

update_product.php

<?php
  
/*
 * Following code will update a product information
 * A product is identified by product id (productId)
 */
  
// array for JSON response
$response = array();
  
// check for required fields
if (isset($_POST['productId']) && isset($_POST['name']) && isset($_POST['description']) && isset($_POST['quantity']) && isset($_POST['price'])) {
  
    $productId = $_POST['productId'];
    $name = $_POST['name'];
    $description = $_POST['description'];
    $quantity = $_POST['quantity'];
    $price = $_POST['price'];
     
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
  
    // connecting to db
    $db = new DB_CONNECT();
  
    // mysql update row with matched pid
    $result = mysql_query("UPDATE product SET name = '$name', description = '$description' , quantity = '$quantity' , price = '$price', dateUpdated = NOW() WHERE productId = $productId");
  
    // check if row inserted or not
    if ($result) {
        // successfully updated
        $response["success"] = 1;
        $response["message"] = "Product successfully updated.";
  
        // echoing JSON response
        echo json_encode($response);
    } else {
  
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
  
    // echoing JSON response
    echo json_encode($response);
}
?>

delete_product.php

<?php
  
/*
 * Following code will delete a product from table
 * A product is identified by product id (productId)
 */
  
// array for JSON response
$response = array();
  
// check for required fields
if (isset($_POST['productId'])) {
    $productId = $_POST['productId'];
  
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
  
    // connecting to db
    $db = new DB_CONNECT();
  
    // mysql update row with matched productId
    $result = mysql_query("DELETE FROM product WHERE productId = $productId");
  
    // check if row deleted or not
    if (mysql_affected_rows() > 0) {
        // successfully updated
        $response["success"] = 1;
        $response["message"] = "Product successfully deleted";
  
        // echoing JSON response
        echo json_encode($response);
    } else {
        // no product found
        $response["success"] = 0;
        $response["message"] = "No product found";
  
        // echo no users JSON
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
  
    // echoing JSON response
    echo json_encode($response);
}
?>

After you fill up the files, you need to install Curl in your machine. Curl is a command line tool for transferring data with URL syntax. Install curl via npm. Type this command to install. If you using windows, run this command in your command prompt. Make sure you install node.js first.

npm install curl

npm install curl

npm install curl

Run this command to test create_product.php in your terminal.

curl POST

curl POST

curl -X POST -F name=The\ Promise\ of\ Spring -F description=With\ Valentine’s\ Day\ come,\ can\ Spring\ be\ far\ behind? -F quantity=3 -F price=21 http://localhost:8888/crud_tutorial/create_product.php

Success status for create_product.php

{"success":1,"message":"Product successfully created."}

Proceed all these curl commands for each URLs

get_product_details.php

curl http://localhost:8888/crud_tutorial/get_product_details.php?productId=1

Success status for get_product_details.php

{
    "success": 1,
    "product": [{
        "productId": "1",
        "name": "The Promise of Spring",
        "description": "With Valentine\u2019s Day come, can Spring be far behind?",
        "price": "21",
        "dateCreated": "2014-02-26 10:26:19",
        "dateUpdated": "2014-02-26 10:26:19"
    }]
}

get_all_products.php

curl http://localhost:8888/crud_tutorial/get_all_products.php

Success status for get_all_products.php

{
    "products": [{
        "productId": "1",
        "name": "The Promise of Spring",
        "description": "With Valentine\u2019s Day come, can Spring be far behind?",
        "quantity": "3",
        "price": "21",
        "dateCreated": "2014-02-26 10:26:19",
        "dateUpdated": "2014-02-26 10:26:19"
    }, {
        "productId": "2",
        "name": "The Rapture of Psyche",
        "description": "Now we're getting a bit more serious!",
        "quantity": "3",
        "price": "21",
        "dateCreated": "2014-02-26 00:00:00",
        "dateUpdated": "2014-02-26 00:00:00"
    }, {
        "productId": "3",
        "name": "Thrilling Love",
        "description": "This girl's got her hockey hunk right where she wants him!",
        "quantity": "3",
        "price": "21",
        "dateCreated": "2014-02-26 00:00:00",
        "dateUpdated": "2014-02-26 00:00:00"
    }],
    "success": 1
}

update_product.php

curl -X POST -F productId=1 -F name=The\ Promise\ of\ Spring -F description=With\ Valentine’s\ Day\ come,\ can\ Spring\ be\ far\ behind? -F quantity=3 -F price=21 http://localhost:8888/crud_tutorial/update_product.php

Success status for update_product.php

{"success":1,"message":"Product successfully updated."}

delete_product.php

curl -X POST -F productId=3 http://localhost:8888/crud_tutorial/delete_product.php

Success status for delete_product.php

{"success":1,"message":"Product successfully deleted"}

I thinks thats all tutorial for a simple web service. Later we will integrate this web service with android app. Stay tune and enjoy!!