ESP8266 NodeMcu Push button to web link

Hello to everyone

I have connected 2 push button with ESP8266 NodeMcu WiFi Board and when i press some of the buttons to I have to access php link. I am taking the individual button count using below url by passig values 1 and 2.

let say

push button 1 -> http://192.168.0.100/smart/webservice.php?func=add&action=1
push button 2 -> http://192.168.0.100/smart/webservice.php?func=add&action=2

I am getting error like

exit status 1
'client' was not declared in this scope

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid     = "test";
const char* pass     = "test@1123";
byte server[] = { 192,168,0,100 }; // mio computer

//Client client(server, 80);
// pin button:
const int button2Pin = 2;     // the number of the pushbutton pin
const int button3Pin = 3;

// variables will change:
int button2State = 0;     
int button2StateOld = 0; // variable for reading the pushbutton status
int button3State = 0;     
int button3StateOld = 0; // variable for reading the pushbutton status


void setup() {
  Serial.begin(115200);
  delay(10);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, pass);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

//int value = 0;

void loop ()
{
  loop1 ();
  loop2 ();
}


void loop1 ()
{
        button2StateOld=button2State;
        button2State = digitalRead(button2Pin);
  
    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (button2State != button2StateOld)  {
                  if (button2State == HIGH){
                           client.connect(); 
                           Serial.println("pin2 high");
                           client.println("POST /smart/webservice.php?func=add&action=1");
                           client.println();
                           client.stop();} 
                    } 

      
          delay (500);//end delay before loop starts again 
}
void loop2 ()
{
        button3StateOld=button3State;
        button3State = digitalRead(button3Pin);
  
    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (button3State != button3StateOld)  {
                  if (button3State == HIGH){
                           client.connect(); 
                           Serial.println("pin3 high"); 
                           client.println("POST /smart/webservice.php?func=add&action=2");
                           client.println();
                           client.stop();} 
                    } 

      
          delay (500);//end delay before loop starts again 

}

Server side code

<?php
ini_set ( 'display_errors', 'off' );
require_once ("connection.php");



$check = true;

if (strstr ( $_SERVER ['HTTP_USER_AGENT'], "UNAVAILABLE" ) != "") {
        $check = true;
}

if ($_GET && $check) {
    if($_GET['func'] == 'add'){
        add_access($_GET['action']);
    }
    if($_GET['func'] == 'get'){
    get_data();
    }
} else {
        echo "<h1>Access Restricted</h1>";
        die ();
}


/**
 * Add Access Log
 * @param string $deviceToken
 */
function add_access($action) {
        $query = "INSERT INTO `access` (`action`, `created_at`) VALUES ('" . $action . "', now());";
                if (mysql_query ( $query ) == 1) {
                        echo "SUCCESS";
                }else{
                echo "FAILED";
                }
        die ();
}

function get_data(){
$query = "SELECT action, count(action) as count FROM access GROUP BY action";
$resultObj=mysql_query($query);
        $action = 0;
        while($row=mysql_fetch_assoc($resultObj))
        {
                $action = $row['action'];
                if($action != ""){
                        if($action == 1){
                        echo "<h1>Button1 : ".$row['count']."</h1>";
                        }else if($action == 2){
                        echo "<h1>Button2 : ".$row['count']."</h1>";
                        }
                }
        }
}
?>

(deleted)

Hi,

did anyone get this code working?

if so please can you help me.

thank you.

What do you think about #2?

Where do you tell the client which server to access?

There are lots of ESP8266 tutorials out there giving you the complete code on how to access specific URLs. Start with that.