ionic 3和MySQL中的POST http:// localhost:8100 / api.php / 404(未找到)

时间:2019-02-19 21:45:17

标签: php mysql angular ionic-framework

我的应用程序试图发布到http://localhost:8100/api.php/,但是遇到404(未找到)错误。

myregst.html

 <ion-list>

    <ion-item>
        <ion-input type="text" placeholder="اسم المستخدم حقيقى" [(ngModel)]="user_name"></ion-input>
      </ion-item>        <ion-item>
          <ion-input type="text" placeholder="رقم هاتف ملك لك " [(ngModel)]="user_phone"></ion-input>
        </ion-item>        <ion-item>
            <ion-input type="password" placeholder="الرقم السري" [(ngModel)]="user_password"></ion-input>
          </ion-item>

    <ion-item>
      <ion-label> اختر المحافظة</ion-label>
      <ion-select  interface="action-sheet"  [(ngModel)]=" user_zone">
        <ion-option   value="GIZA" > GIZA </ion-option>
      </ion-select>
    </ion-item>
    <ion-item>
      <ion-label> اختر المدينة</ion-label>
      <ion-select  interface="action-sheet" [(ngModel)]=" user_city">
        <ion-option   value="DOQI" > DOQI </ion-option>
      </ion-select>
    </ion-item>
    <ion-item>
      <div padding>
        <button ion-button color="primary" block (click)="lognew()" > تسجيل  </button>

      </div>

    </ion-item>

  </ion-list>

myregst.ts

    lognew(){
    if(this.user_name==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى ادخال الاسم صحيح',
        duration: 3000
      });
      toast.present();
    }else if(this.user_phone==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى ادخال رقم  هاتفك',
        duration: 3000
      });
      toast.present();
    }else if(this.user_password==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى كتابة الرقم السري',
        duration: 3000
      });
      toast.present();
    }else if(this. user_zone==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى اختيار المحافظة ',
        duration: 3000
      });
      toast.present();
    }else if(this. user_city==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى اختيار  المنطقة',
        duration: 3000
      });
      toast.present();
    }else{

      let body ={
        user_zone: this.user_zone,
        user_city: this.user_city,
        user_phone: this.user_phone,
        user_name: this.user_name,
        user_password: this.user_password,
        akis:'add'
      };
      this.ConPro.usernew(body,'api.php/').subscribe( data => {
         var alartpesan = data.msg;
        if(data.success){
          this.navCtrl.pop();
          const toast = this.toastCtrl.create({
            message: 'add succesful',
            duration: 3000
          });
          toast.present();

        }else{
          const toast = this.toastCtrl.create({
            message: alartpesan,
            duration: 3000
          });
          toast.present();
        }

      });

    }
}

providers.ts

 import { HttpClient } from '@angular/common/http';
import { Http , Headers,RequestOptions } from '@angular/http';

 import { Injectable } from '@angular/core';
 import 'rxjs/add/operator/map';
/*
Generated class for the RecipesProvider provider.

  See https://angular.io/guide/dependency-injection for more info on 
 providers
and Angular DI.
*/
@Injectable()
export class RecipesProvider {
 ask: string


 constructor(public HttpClient: HttpClient ,public Http: Http ) {

   this.ask = "http://localhost/blueapp/"

 }

  usernew(body:any, file:any) {
  let type = "application/json; charset=UTF-8";
  let headers = new Headers({ 'Content-Type': type });
  let options = new RequestOptions({ headers: headers });
  return this.Http.post(this.ask=file,JSON.stringify(body),options).map(res => res.json());

}

}

db.php

<?php
$db = new mysqli("localhost","root","","tabkh");
$db->query("set names utf8");

api.php

<?php
include ("db.php");
 header("Access-Control-Allow-Origin: *");
 header("Access-Control-Allow-Credentials: true");
 header("Access-Control-Allow-Methods: POST,GET,OPTIONS");
 header('Access-Control-Allow-Headers: Content-Type,Authorization, X- 
 Requested- 
  With');
   header("Content-Type: application/json; charse=utf-8");



$postjson = json_decode(file_get_contents('php://input'), true);
if($postjson['akis'] == 'add'){`
 $password = md5($postjson['password']);
 $query =( "INSERT INTO user SET 
        user_zone = '$postjson[user_zone]',
        user_city = '$postjson[user_city]',
        user_phone = '$postjson[user_phone]',
        user_name = '$postjson[user_name]',
        user_password=' $postjson[user_password]',
        echo $postjson[user_zone];
 ");
  if($query) $result = json_encode(array('success'=>true));
else $result = json_encode(array('success'=>false ,'msg' => 'error ,plase 
 tru agin' ));
echo  $result;
};

错误图片

Error displayed

1 个答案:

答案 0 :(得分:0)

问题是您的URL中的尾部斜杠:

this.ConPro.usernew(body,'api.php/')

应该是:

this.ConPro.usernew(body,'api.php')