角材料.如何将参数传递给 PHP? [英] Angular Material. How do I pass a parameter to PHP?

查看:28
本文介绍了角材料.如何将参数传递给 PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Angular Material 中复制一个应用程序,该应用程序已经使用 HTTP/JavaScript 等运行了几年.该应用程序可以称为数据库类型应用程序,对远程服务器上的 MySQL 数据库执行 CRUD 操作在应用程序和数据库之间使用 PHP.

I am trying to replicate an app in Angular Material that I have had running for a couple years with HTTP/JavaScript etc. The app is what could be called a database type app with CRUD operations on a MySQL database on a remote server which uses PHP between the App and the Database.

服务器以 JSON 格式返回的几个表受 JavaScript 发送的参数范围限制,然后由 PHP 接收,并在 Select 语句的 where 子句中使用,如以下代码片段:

Several of the tables which are returned from the server in JSON are range limited by a parameter sent from the JavaScript, and then received by the PHP, and used in the where clause of the Select statement like this code snippet:

$registration      = $_POST['REGISTRATION'] ;
$query  = "SELECT sysid, REGISTRATION, TYPE, COMPONENT, SERIAL, PART_NUMBER FROM status_hours WHERE REGISTRATION='$registration' ";

此 HTTP/JavaScript/PHP 代码运行良好,但我想在 Angular Material 中复制该应用程序.

This HTTP/JavaScript/PHP code is working perfectly, however I would like to replicate the app in Angular Material.

使用 Angular Material 我可以完美地检索 JSON 中的记录,但问题是我无法发送参数并使其工作,以便它可以在 PHP 的 WHERE 子句中使用.

With Angular Material I can retrieve recors in JSON perfectly, but the problem is that I can not send a parameter and get it working so that it can be used in the WHERE clause in the PHP.

这是应用程序上的 Type Script 代码,它从服务器获取行表.

Here is the Type Script code on the app which gets a table of rows from the server.

const url     = 'http://mydatabase.com/angular/php/status_hours.php'               ;
    const options = { params: new HttpParams().set('REGISTRATION', this.REGISTRATION) }   ;
    this.http.get<Hours[]> (url, options)
    .subscribe(hours => 
    {
        console.log(hours)            ;
        this.dataSource.data = hours  ; 
    } )  ;

这是我尝试过的 PHP 代码,用于接收名为 REGISTRATION 的参数,以便它可以在 WHERE 语句中使用.

Here is the PHP code I have tried, to receive the parameter which is called REGISTRATION so that it can be used in the WHERE statement.

$postdata   = file_get_contents("php://input");
$request    = json_decode($postdata);
$registration   = $request->REGISTRATION;

问题是 Angular 应用程序没有发送参数,或者 PHP 没有接收到参数,以便它可以在 WHERE 子句中使用.
我可以硬编码用于求和目的, $registration = 'hardCodedData' ;它将返回有效的 JSON 数据.

The problem is either the parameter is not being sent by the Angular app, or it is not being received by the PHP so that it can be used in the WHERE clause.
I can hardcode for sumulation purposes, $registration = 'hardCodedData' ; and it will return valid JSON data.

感谢您的帮助.

推荐答案

这是我用来传递多个参数的链接.相同的 PHP 代码当然适用.

Here is a link which I have used to enable me to pass multiple parameters. The same PHP code applies of course.

Angular 4 HttpClient 查询参数

这篇关于角材料.如何将参数传递给 PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆