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):
void 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:
function 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