Use recovered value from MySQL database

Hello, I´m not fully experienced in English so sorry for possible bad language. I have an Arduino Uno + Ethernet Shield W5100 and my code doesn´t do what I want it to do: remote control ON/OFF of two leds from anywhere through Internet, I mean an IoT application.
For do this, I designed an application in Android Studio which has 4 buttons, one for turn ON the first led, one for turn OFF the same led, one for turn ON the second led, and one for turn OFF this second led.
My idea is turn ON or turn OFF two leds at will from this application. First, I press one of the four buttons and send a character to MySQL database hosted in a web hosting (for now, 000webhost, for tests), this character will be:
1 if I press first button
2 if I press second button
3 if I press third button
4 if I press fourth button
I achieve this using a php file uploaded to the hosting.
Then, Arduino retrieve this character and do the action.
My actual code is based in example WebClientRepeating, with this I see in the serial that Arduino can retrieve the character but it doesn´t do the action.
This is my code:

#include <SPI.h>
#include <Ethernet.h>

char valor;
char ledPin5 = 5;
char ledPin6 = 6;
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

EthernetClient client;

char server[] = "";

unsigned long lastConnectionTime = 0;             // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
// the "L" is needed to use long type numbers

void setup() {
  // start serial port:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  // give the ethernet module time to boot up:
  // print the Ethernet board/shield's IP address:
  Serial.print("My IP address: ");

void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c =;
    if (Serial.available()>0){
    valor =;
    if (valor=='1'){
    else if (valor=='2'){
    else if (valor=='3'){
    else if (valor=='4'){

  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {


// this method makes a HTTP connection to the server:
void httpRequest() {
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    // send the HTTP GET request:
    client.println("GET /pruebaz.php HTTP/1.0");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");

    // note the time that the connection was made:
    lastConnectionTime = millis();
  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");

And this is the serial response (after I pulse the second button in my app):

My IP address:
HTTP/1.1 200 OK
Date: Fri, 03 Aug 2018 00:37:19 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Server: awex
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Request-ID: afc7fabddc65a7f50c0bcefefab98b5f


The another php file I use to recover the character is pruebaz.php:

$conexion = mysqli_connect("xxxxxxxx","xxxxxxxx","xxxxxxxxx","xxxxxxxx");

$consulta = "SELECT valor FROM botones WHERE tiempo=(SELECT max(tiempo) FROM botones)";
$resultado = mysqli_query($conexion,$consulta);
if (mysqli_num_rows($resultado)>0) {
	$row = mysqli_fetch_assoc($resultado);
	echo "" .$row["valor"]. "";

When I execute it in the browser (, it shows me just the character: 2

Looks like the problem is in the Arduino code. Hope you can help me. Thanks for your time reading this.

if (client.available()) {
    char c =;
    if (Serial.available()>0){
    valor =;
    if (valor=='1'){

You have a value in variable c, you write it to Serial, then you read It back in, then you attempt to use it. Why not just use c directly ?

if (client.available()) {
    char c =;
    if (c=='1'){

ok thanks there is led action now but with a diferent response that I expect:

pressing first button (for led1 ON in pin digital 5): it gets ON as I expect but led2 gets randomly ON or OFF in every loop
pressing second button (for led1 OFF): it gets OFF as I expect but led2 continues randomly
pressing third button (for led2 ON in pin digital 6): same as first button (as I expect but random led1)
pressing fourth button (led2 OFF): same as second button (as I expect but random led1)

also there is a little blink between every loop
and the response of the led when I press the button in the app is not as fast as I expect, that´s the delay, right? should I decrease the delay?

It will be quite unresponsive because it looks like the postingInterval is designed for a 10 second cycle (OK if you are logging data, but not if you want a led to be quite responsive to a remote button press).

The delay() bin setup() is not the problem.

Try reducing postingInterval say to 500mS.

ok the time response button pulsed - led action is better now (more realistic) but the led response keeps uncertain. I reduced postingInterval to 500ms and proved with 200ms too, in both I got same response:

pressing first button: as expected turns ON led1 (but there's a little blink for every loop) and led2 acts uncertainly (sometimes turns ON randomly every loop, sometimes blinks and sometimes keeps OFF as I expect)

pressing second button: same as first button but applied to this case: turns OFF led1 and randomly ON/OFF led2, the blink continues in both leds for every loop

pressing third button: same applied, the blink continues in both leds for every loop

pressing fourth button: same apllied, the blink continues in both leds for every loop