title: Ionic 3 posting data to Mysql
body: <p>i am new to Ionic 3,i want to submit he username data to mysql. I am using the following code, it does not show any error message, but it does not show the value submitted to api.php file. How we can use the Insert command in the following api.php file.</p>
  
  <p><strong>contact.html</strong></p>
  
  <pre><code>&lt;ion-header&gt;
    &lt;ion-navbar&gt;
      &lt;button ion-button menuToggle&gt;
        &lt;ion-icon name="menu"&gt;&lt;/ion-icon&gt;
      &lt;/button&gt;
      &lt;ion-title&gt;My Contact&lt;/ion-title&gt;
    &lt;/ion-navbar&gt;
  &lt;/ion-header&gt;
  
  &lt;ion-content padding&gt;
   &lt;ion-list&gt;
    &lt;ion-item&gt;
      &lt;ion-label floating&gt;Username&lt;/ion-label&gt;
      &lt;ion-input type="text" name="username" [(ngModel)]="data.username"&gt;&lt;/ion-input&gt;
    &lt;/ion-item&gt;
  &lt;button ion-button color="danger" round (click)="submit()"&gt;Submit&lt;/button&gt;
  &lt;button ion-button color="primary" menuToggle&gt;Toggle Menu&lt;/button&gt;
  &lt;/ion-list&gt;
    &lt;/ion-content&gt;
  </code></pre>
  
  <p><strong>contact.ts</strong></p>
  
  <pre><code>import { Component } from '@angular/core';
  import { IonicPage, NavController, NavParams } from 'ionic-angular';
  import { Http } from '@angular/http';
  /**
   * Generated class for the ContactPage page.
   *
   * See http://ionicframework.com/docs/components/#navigation for more info
   * on Ionic pages and navigation.
   */
  
  @IonicPage()
  @Component({
    selector: 'page-contact',
    templateUrl: 'contact.html',
  })
  export class ContactPage {
    data:any = {};
    constructor(public navCtrl: NavController, public navParams: NavParams,  public http: Http) {
    this.data.username = '';
    this.data.response = '';
    this.http=http;
   }
  
  submit() {
   var link = '../contact/api.php';
   var myData = JSON.stringify({username: this.data.username});
   this.http.post(link, myData)
   .subscribe(data =&gt; {
   this.data.response = data["_body"]; 
   }, error =&gt; {
   console.log("Oooops!");
   });
   }
    ionViewDidLoad() {
      console.log('ionViewDidLoad ContactPage');
    }
  
  }
  </code></pre>
  
  <p><strong>api.php</strong></p>
  
  <pre><code>&lt;?php
      // Allow from any origin
      if (isset($_SERVER['HTTP_ORIGIN'])) {
          header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
          header('Access-Control-Allow-Credentials: true');
          header('Access-Control-Max-Age: 86400');    // cache for 1 day
      }
  
      // Access-Control headers are received during OPTIONS requests
      if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  
          if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
              header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         
  
          if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
              header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  
          exit(0);
      }
  
      echo "You have CORS!";
  
      $postdata = file_get_contents("php://input");
      if (isset($postdata)) {
          $request = json_decode($postdata);
          $username = $request-&gt;username;
          echo "hello how are you"
          if ($username != "") {
              echo "Server returns: " . $username;
          }
          else {
              echo "Empty username parameter!";
          }
      }
      else {
          echo "Not called properly with username parameter!";
      }
  ?&gt;
  </code></pre>
  
  <p>Please Help to solve the problem</p>