'POST data ESP8266 With RFID Card MFRC522 Using PHP MVC

I'm having trouble trying to enter the results of the rfid scan into the database using esp8266, for the error result is in the image I attached. In this case I am using PHP MVC.

Thank you.

This my code esp8266 :

#include <SPI.h>
#include <MFRC522.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>

#define SS_PIN D2  //--> SDA / SS is connected to pinout D2
#define RST_PIN D1  //--> RST is connected to pinout D1

MFRC522 mfrc522(SS_PIN, RST_PIN);

const char* ssid = "My WiFi";
const char* password = "MyPassword";

String content;

void setup() {
  Serial.begin(115200);
  SPI.begin();
  mfrc522.PCD_Init();
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting..");
  }
  Serial.println("");
  Serial.print("Successfully connected to : ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  Serial.println("Please tag a card or keychain to see the UID !");
  Serial.println("");
}

void loop () {
  if (WiFi.status() == WL_CONNECTED) {
    if ( ! mfrc522.PICC_IsNewCardPresent())
    {
      return;
    }
    if ( ! mfrc522.PICC_ReadCardSerial())
    {
      return;
    }
    Serial.println();
    Serial.print("UID tag :");
    content = "";
    byte letter;

    for (byte i = 0; i <mfrc522.uid.size; i++)
    {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
      Serial.print(mfrc522.uid.uidByte[i], HEX);
      content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : ""));
      content.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    content.toUpperCase();
    Serial.println();
    kirim();
  } else {
    Serial.println("Error in WiFi connection");
  }
}

void kirim()
{
  HTTPClient http;    //Declare object of class HTTPClient
 
  String ValueSend, postData; //Read Analog value of LDR
  ValueSend = String(content);   //String to interger conversionapp
 
  //Post Data
  postData = "uid=" + ValueSend;
  
  http.begin("http://192.168.3.20/perpus-smk-bhakti-anindya/app/controllers/GetUID.php");
//  http.begin("http://192.168.1.3:8000/UIDresult");
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");    //Specify content-type header
 
  int httpCode = http.POST(postData);   //Send the request
  String payload = http.getString();    //Get the response payload

  //Serial.println("uid=" + ValueSend);
  if (httpCode > 0)
  {
    Serial.println(payload);
  } else
  {
    Serial.print("Error on sending POST: ");
    Serial.println(httpCode);
  }
  delay(2000);
  http.end();  //Close connection
}

This my code using php mvc :

Controller PHP MVC

<?php

class GetUID extends Controller {
    public function index()
    {
        if(isset($_POST['uid'])) {
            $uid = $_POST["uid"];
            $this->model('GetUID_model')->getEntryUIDfromESP($uid);
        }
    }

    // public function GetUIDfromESP()
    // {
    //     $this->model('GetUID_model')->getEntryUIDfromDB();
    // }
}

Model PHP MVC

<?php

class GetUID_model {
    private $table = 'uid_entry';
    private $db;

    public function __construct()
    {
        $this->db = new Database;
    }

    public function getEntryUIDfromESP($uid)
    {
        $query = "INSERT INTO uid_entry VALUES (null, uid_card)";

        $this->db->query($query);
        $this->db->bind('uid_card', $uid);

        $this->db->execute();

        return $this->db->rowCount();
    }
    
    // public function getEntryUIDfromDB()
    // {
    //     $this->db->query('SELECT * FROM ' .$this->table);
    //     $hasil = $this->db->single();
    //     echo $hasil['uid_card'];
    // }
}

Display Error In Serial Monitor Arduino IDE Display Error In Serial Monitor Arduino IDE



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source