GET request not working, not updating the MySQL database (ESP32 and web hosting)

Hello everyone, I am facing problems while uploading data to MySQL database.
I have created my own domain name using "infinityfree.net" hosting service.

I have created MySQL database and a PHP code to upload values in the PhpMyAdmin database.

Here is my ESP32 code:

#include <WiFi.h>
const char* ssid     = "NetGear";
const char* password = "*123phoenix";
const char* host = "assetmanagement.epizy.com";
String tagID = "123ABC", RTCtime2 = "2020-09-18%2018:58:54";
void setup() {
  Serial.begin(115200);
  delay(1000);
  WiFi.begin(ssid, password);
  if (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
  }
}
void loop() {
  if (WiFi.status() != WL_CONNECT_FAILED) {
    WiFiClient client;
    const int httpPort = 80;
    Serial.println(client.connect(host, httpPort));
    if (!client.connect(host, httpPort)) {
      Serial.println("connection failed");
      return;
    }
    if (tagID = "123ABC") {
      client.print(String("GET http://assetmanagement.epizy.com/connect.php?") +
                   ("tagID=") + tagID + ("&RTCtimestamp=") + RTCtime2 +
                   " HTTP/1.1\r\n" +
                   "Host: " + host + "\r\n" +
                   "Connection: Close\r\n\r\n");
      Serial.print(String("GET http://assetmanagement.epizy.com/connect.php?") +
                   ("tagID=") + tagID + ("&RTCtimestamp=") + RTCtime2 +
                   " HTTP/1.1\r\n" +
                   "Host: " + host + "\r\n" +
                   "Connection: Close\r\n\r\n");
      Serial.println("Database updated");
      unsigned long timeout = millis();
      while (client.available() == 0) {
        if (millis() - timeout > 1000) {
          Serial.println(">>> Client Timeout !");
          client.stop();
          return;
        }
        // Read all the lines of the reply from server and print them to Serial
        while (client.available()) {
          String line = client.readStringUntil('\r');
          Serial.print(line);
        }
        Serial.println();
        Serial.println("closing connection");
        tagID = "";
      }
    }
  }
}

And Here is my PHP code:

<?php
class gate2{
 public $link='';
 function __construct($tagID, $RTCtimestamp){
  $this->connect();
  $this->storeInDB($tagID, $RTCtimestamp);
 }
 
 function connect(){
  $this->link = mysqli_connect('sql302.epizy.com','epiz_26766463','password') or die('Cannot connect to the DB');
  mysqli_select_db($this->link,'epiz_26766463_database') or die('Cannot select the DB');
 }
 
 function storeInDB($tagID, $RTCtimestamp){
  $query = "insert into gate2 set TagID='".$tagID."' , Timestamp='".$RTCtimestamp."'";
  $result = mysqli_query($this->link,$query) or die('Errant query:  '.$query);
 }
 
}
if($_GET['tagID'] != '' and $_GET['RTCtimestamp']!=''){
 $gate2=new gate2($_GET['tagID'],$_GET['RTCtimestamp']);
}

?>

Serial monitor output:

1
GET http://assetmanagement.epizy.com/connect.php?tagID=123ABC&RTCtimestamp=2020-09-18%2018:58:54 HTTP/1.1
Host: assetmanagement.epizy.com
Connection: Close

Database updated

closing connection

closing connection

My Credentials are:
MySQL host: sql302.epizy.com
MySQL Database: epiz_26766463_database
MySQL Table name: gate2
Username: epiz_26766463
Password: password
Domain name: assetmanagement.epizy.com

Here, the database is not being updated and when I manually put the same URL in search bar, database is updated. Also, This same code works for "localhost". What am I doing wrong here?

Can you view the web server log files to see what is getting through?
Also search for “URL safe characters”. For example, the “%” may give problems.

use library to make things handy
add

#include <HTTPClient.h>

at the top as header

and

HTTPClient http;
String urlPath = "http://assetmanagement.epizy.com/connect.php?tagID=" + tagID + "&RTCtimestamp=" + RTCtime2; 

http.begin(urlPath);
int httpCode = http.GET();  
Serial.println(httpCode);

if ( httpCode == 200 ) {
String payload = http.getString();
Serial.println(payload);
}

http.end();

whenever you want to hit a request

like 6v6gt said, avoid using % as it's used for 'http encoding'

more from here ESP32: HTTP GET Requests - techtutorialsx

I tried using HTTPCient.h library and I am getting this output:

HTTP Response Code: 200
<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("5c0298a1ec25df0f5f6e06fabae9237b");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://assetmanagement.epizy.com/connect.php?tagID=1D0080A5EAD2&RTCtimestamp=2020-9-19%2012:18:22&i=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>
Database updated
closing connection

I also removed the % sign from code, but still database is not updated.

"This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support" this line tells me that I require javascript for the Client server but ESP can not do Javascript (correct me if I'm wrong).

Now what should I do? I know this code works on Apache server but then I will have to use "localhost" , won't I?

I dont want to use localhost beacause then ESP has to be connected to computer'wifi. basically if I disconnect Computer's WiFi then ESP's WiFi also gets disconnected. Is there any way to avoid this?

Yes, but you got these two lines in the results:

Database updated
closing connection

which appear also when you attempt to issue the same URL on a browser search bar.
I think you can ignore the "missing java script" message.

The "Database updated" message could appear before it has validated everything, so may be premature.

You obviously have some level of access to the server to be able to add PHP code.
Either look in the Apache log files for your connection attempts, or create a simple PHP program which writes back the parameters given to it, so you can inspect these.

Also, to ensure that it is your PHP that is being run, pass some bad parameters to it to provoke it into issuing messages such as 'Cannot connect to the DB' etc.