多列插入数据库中

时间:2016-06-24 14:06:40

标签: http angular

我在TypeScript for Angular 2中编写了一些代码。当我点击提交按钮时,数据会附加到数据库,但数据库中显示的值是错误的

只需点击一下,我的数据库就会插入4行,其中包含1行有效数据,其他3行包含空值。

这是我的组成部分:

import {Component} from '@angular/core';
import {Http, Response, Headers} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {Subject } from 'rxjs/Subject';
@Component({
    templateUrl: './components/profile/profile.html'
})

export class Profile {
    http: Http;

    constructor(http: Http) {
        this.http = http;
    }
    postResponse = new Person();

    onSubmit(form){
        //this.form = form;
        console.log(form);
        var headers = new Headers();
        //  headers.append('Content-Type', 'application/json');
        headers.append('Content-Type','application/x-www-form-urlencoded')

        this.http.post('http://localhost/fin/index.php/profile/addprofile', JSON.stringify(form),{headers:headers})
            .map((res: Response) => res.json())
            .subscribe((res:Person) => this.postResponse = res);
    }
}
class Person {
    firstName:string;
    lastName:string;
}

我的模板

    <h3 class= "head">MY PROFILE</h3>

 <form (ngSubmit)="onSubmit(myForm.value)" #myForm="ngForm" >


  <div class="form-row">
          <div class="col-lg-6" >
<div class="formHeading get">First Name</div>
<input type="text" id="firstName" class = "col-sm-7" ngControl="firstname"> 
 </div>

  <div class="form-row">
   <div class="col-lg-6" >
    <div class="formHeading get" >Last Name</div>
    <input type="text" id="firstName" class = "col-sm-7" ngControl="lastname">

 <div class="form-row">
   <div class="col-lg-6" >
   <div class="formHeading get">Email</div>
<input type="text" id="zip" class = "col-sm-7"  ngControl="email">

   

<div class="form-row">
   <div class="col-lg-6" >
<div class="formHeading get">Profile Name</div>
<input type="text" id="profileName" class = " col-sm-7"    ngControl="profilename">

  <div class="form-row">
   <div class="col-lg-6" >
<div class="formHeading get">Contact Number</div>
<input type="text" id="firstName" class = " col-sm-7" ngControl="phone">

  

    保存    

我不确定错误的位置,有时我会在数据库中看到正确的数据,有时却看不到。任何人都可以找到错误吗?

0 个答案:

没有答案