Problem with php and mysql on http POST part of php file runs an another doesn't

Im using an Arduino to read code from GM65 module via UART, with these code in void loop:

  if(GM65.available()){
  String barcode=GM65.readStringUntil('\n');
         Serial.print(barcode);
String PostData = "code="+barcode; ..

Then I SEND THE QR read (barcode) TO A PHP file in a server which captures the data and store in in a SQL DB. Upon there everything is fine... The code stored in the DB is the same as de one in the QR read previously.

  http.begin(client, URL_SERVER); ¿
  http.addHeader("Content-Type", "application/x-www-form-urlencode");   
  int httpResponseCode = http.POST(PostData);

  Serial.print("Codigo Respuesta HTTP: "); 
  Serial.printf("[HTTP] POST...  %s\n", http.errorToString(httpResponseCode).c_str());
  Serial.println(httpResponseCode); 
if(httpResponseCode==200){
       digitalWrite(LED_INTEGRADO, HIGH);
    delay(1000);
      digitalWrite(LED_INTEGRADO, LOW);
    delay(1000);
       digitalWrite(LED_INTEGRADO, HIGH);
    delay(1000);
      digitalWrite(LED_INTEGRADO, LOW);
    delay(1000);
    }

PHP file start:

if(!empty($_POST)) {
    $idQR=$_POST['code'];
 $sql1 = "INSERT INTO tmp (id,value) values (DEFAULT, {$idQR})" ;
    $link=conenect();
    $result = mysqli_query($link, $sql1);

Problem starts when latter on the same php file on the server I want to execute other php instruction (like an if to compare inserted qr code with existent qr code in another table which data I have previously SELECTED ).

If I send the qr code from a html form with a input type text everything gets executed as expected, and the rest of php file runs fine if I send the qr code form the post command in Arduino, it seems that only the INSERT command is executed in the PHP.

Maybe I missing something important here but I have 2 questions/ probable causes for these behavior:
¿When I send a POST to a php file in a server via arduino, does the hole php get executed in the same way as when I send it from a html form?.

¿The String data send from the PostData via arduino, is the same as a TEXT input in a form or maybe I am receiving something extra in the POST (rubbish data, special character, etc) that gets ignored when INSERTING IN THE DB via de SQL INSERT but is taken into account in the if so upon evaluating the condition does not get true when I send the post via Arduino?

Any help regarding these topic will be much appreciated.

Problem solved by trimming trim($idQR); in the input data from de Arduino on the php form ... apparently it was sending to the php inside the post a space or a /n at the end of the string

POST can be closed.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.