So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Erick Del Mundo
#81906 Hi I'm just a newbie and found an online tutorial about basic attendance system https://devcraze.com/tutorials/connecting-rfid-scanner-to-php-using-nodemcu-wifi-module/, I'm using Esp8266 NodeMcu, RFID Rc522 as material then Arduino Core and PHP as programming tool, its working properly but how can I send an alert message like:
echo "<script>alert('Successfully Login');<script>";

or if failed:

echo "<script>alert('Unable Login');<script>";

aside from:

if(payload.equals("success")) {
digitalWrite(SUCCESS_PIN, HIGH);
} else {
digitalWrite(ERROR_PIN, HIGH);
}

This is the code I used in Arduino core to program ESP8266 (NodeMCU):
Code: Select allvoid sendRfidLog(long cardId) {
 
  if(WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String postData = "cardid=" + String(cardId) + "&action=insertRfIdLog";
    http.begin("http://192.168.1.6/rfid/log.php");           
    http.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
   
    int httpCode = http.POST(postData);
    String payload = http.getString();
    Serial.println(httpCode);
    Serial.println(payload);
   
    if(payload.equals("success")) {
     digitalWrite(SUCCESS_PIN, HIGH);
    } else {
     digitalWrite(ERROR_PIN, HIGH);
    }
   
    http.end();
  }
}


and the code in PHP:

Code: Select allfunction insertRfIdLog() {
    include 'connect.php';
    $cardid = $_POST['cardid'];
    $time = time();
   
    $stmt = $conn->prepare("INSERT INTO `tbllogs`(`cardid`, `logdate`) VALUES (:card, :dt)");
    $stmt->bindParam(":card", $cardid);
    $stmt->bindParam(":dt", $time);
   $stmt->execute();
   
   echo "success"; // I want this part to become an alert message like echo "<script>alert('Successfully login');</script>"; then REFRESH the page after clicking the OK button of the alert message
}

Thank you in advance