HTTP/1.1 400 Bad Request

Hello!
My project is to save sensor data to mysql database.
Devices:

  • Arduino UNO
  • W5100 Ethernet shield
  • (TCRT5000)

test code:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x04 };

IPAddress server(192,168,0,106);
IPAddress ip(192,168,0,177);
EthernetClient client; 

/* Setup for Ethernet and RFID */

void setup() {
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }
  Serial.print("LAN IP            : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP     : ");
  Serial.println(Ethernet.dnsServerIP());
  delay(1000);
}

void loop(){
  Sending_To_phpmyadmindatabase(); 
  delay(5000); // interval
}


 void Sending_To_phpmyadmindatabase()   //CONNECTING WITH MYSQL
 {
   if (client.connect(server,80)) {
    Serial.println("connected");
    // Make a HTTP request:
    Serial.println("GET /testcode/code.php?sensor=lot3&action=lot left");
    client.println("GET /testcode/code.php?sensor=lot3&action=lot left HTTP/1.1");
    client.println("Host: 192.168.0.106");
    delay(1000);
    if(client.available()) {
      Serial.println("ARDUINO: HTTP message received");
      Serial.println("ARDUINO: printing received headers and script response...\n");

      while(client.available())
      {
          char c = client.read();
          Serial.print(c);
      }
    } else {
      Serial.println("ARDUINO: no response received / no response received in time");
    }
    client.println("Connection: close");
    client.println();
    client.stop();
    
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
    
  }
 }

code.php

<?php
class logging{
 public $link='';
 function __construct($sensor, $action){
  $this->connect();
  $this->storeInDB($sensor, $action);
 }
 
 function connect(){
  $this->link = mysqli_connect('localhost','root','') or die('Cannot connect to the DB');
  mysqli_select_db($this->link,'test') or die('Cannot select the DB');
 }
 
 function storeInDB($sensor, $action){
  $query = "insert into testdata (sensor, action) VALUES ('".$sensor."', '".$action."')";
  $result = mysqli_query($this->link,$query) or die('Errant query:  '.$query);
 }
 
}
if($_GET['sensor'] != '' and  $_GET['action'] != ''){
 $logging=new logging($_GET['sensor'],$_GET['action']);
}


?>

and the result from serial monitor

LAN IP            : 192.168.0.102
Subnet Mask       : 255.255.255.0
Default Gateway IP: 192.168.0.1
DNS Server IP     : 192.168.0.1
connected
GET /testcode/code.php?sensor=lot3&action=lot left
ARDUINO: HTTP message received
ARDUINO: printing received headers and script response...

HTTP/1.1 400 Bad Request
Date: Mon, 20 Apr 2020 09:41:20 GMT
Server: Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
Vary: accept-language,accept-charset
Accept-Ranges: bytes
Connection: close
Content-Type: text/html; charset=utf-8
Content-Language: en
Expires: Mon, 20 Apr 2020 09:41:20 GMT

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Bad request!</title>
<link rev="made" href="mailto:postmaster@localhost" />
<style type="text/css"><!--/*--><![CDATA[/*><!--*/ 
    body { color: #000000; background-color: #FFFFFF; }
    a:link { color: #0000CC; }
    p, address {margin-left: 3em;}
    span {font-size: smaller;}
/*]]>*/--></style>
</head>

<body>
<h1>Bad request!</h1>
<p>


    Your browser (or proxy) sent a request that
    this server could not understand.

</p>
<p>
If you think this is a server error, please contact
the <a href="mailto:postmaster@localhost">webmaster</a>.

</p>

<h2>Error 400</h2>
<address>
  <a href="/">localhost</a>

  <span>Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30</span>
</address>
</body>
</html>

How can I resolve this problem?
/Thanks in advance/

Could be a missing encoding.

client.println("GET /testcode/code.php?sensor=lot3&action=lot%22left HTTP/1.0");

Unfortunately it doesn't work. Niether with %22 nor %20.
And the result is

connected
GET /testcode/code.php?sensor=lot3&action=lot left
ARDUINO: no response received / no response received in time

Probably a missing line break at the end of the request header.

"My project is to save sensor data to mysql database."

Is the URL to the database HTTP or HTTPS?