Data[‘_body’] shows only first ID in console from MySql DB back-end mysqli PHP echo


#1

Hello,

Need your help to figure out, what can be reason of this problem:

I have MySql database login table:

ID | name  | username
------------------------
1  | sally | sally123
2  | jack  | jack120
3  | leila | leila77
4  | aaron | aaron800 
5  | sara  | sara444

Also I have equivalent PHP file with search by input of $name = $_POST['name'];

If my ID variable is id: number = 4; Chrome console with data['_body'] echo is Result: Name: Aaron Username: aaron800 if id is 3, it is Result: Name: leila Username: leila77 etc., it was equal record by equal inserted ID or name, code worked properly.

Without any changes or installs in project, as well as changes or updates on server with PHP version or MySql, it start to work wrong way.

If I insert id: number = 5;, 2,1 or 4… it is always first record with ID 1 in console: Result: Name: Sally Username: sally123. Same with $name = $_POST['name']; different inputs: name: string = 'sara';, jack, leila…in result I got first record: Result: Name: Sally Username: sally123.

  byID() {
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers });

    let postParams = '&ID=' + this.id; 

    this.http.post("http://site.info/php/byid.php", (postParams), options)
      .subscribe(data => {
        console.log('Result:', data['_body']);        
      }, error => {
        console.log(error);
      });
  }

What did I do after this problem appeared:

  1. It was a working PHP, but to check I’ve changed $query = "SELECT name, mobile FROM login ORDER BY id='$ID'"; instead of ...ORDER BY ID";. It doesn’t makes sense, same result.

  2. I’ve checked MySql and PHP version on server. Nothing was changed there.

  3. Despite previous, I have test it with two different server connections fromthis.http.post with same database and appropriate PHP files on both, but I got same result.

  4. I have tried to create new project, but this also did not change anything.

  5. I know from this answer Attach data[’_body’] value with variable to use it in another function that I have to put interaction with the network in a provider. Sure, it is proper way, but I’m wondering, if it is a reason of particular problem, or what can be cause of problem with particular code, which worked fine and just stopped to work.

I don’t have idea, how to figure out with this problem


Attach data['_body'] value with variable to use it in another function