Send GET PHP with Arduino

Hi i want send GET request to my page.php but i have error, this is arduino code:

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

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 

IPAddress ip(192,168,1,101);
 
EthernetClient client;
 
char server[] = "arduinoalter.altervista.org/NuovoFile.php";
 
 
void setup()
{
  Serial.begin(9600);
 
  // attempt a DHCP connection:
  Serial.println("Attempting to get an IP address using DHCP:");
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println("failed to get an IP address using DHCP, trying manually");
    Ethernet.begin(mac, ip);
  }
 
  Serial.print("My address:");
  Serial.println(Ethernet.localIP());
}
 
 
void loop()
{
    // connect to the server
    if (client.connect(server, 80))
    {
        // print to serial monitor
        Serial.println("connected...");
        Serial.println("ARDUINO: forming HTTP request message");
 
        // send data the server through GET request
        client.print("GET http://arduinoalter.altervista.org/NuovoFile.php?user=12");
        client.println(" HTTP/1.1");
        client.print("HOST: ");
        client.println(server);
 
        Serial.println("ARDUINO: HTTP message sent");       
 
        // give server some time to receive and store data
        // before asking for response from it
        delay(1000);
 
        // get the response from the page and print it to serial port
        // to ascertain that data was received properly
        if(client.available())
        {
            Serial.println("ARDUINO: HTTP message received");
            Serial.println("ARDUINO: printing received headers and script response...\n");
 
            while(client.available())
            {
                char c = client.read();
                Serial.print(c);
            }
        }
        else
        {
            Serial.println("ARDUINO: no response received / no response received in time");
        }
 
        client.stop();
    }
    // do nothing forever after:
    while(true);
}

in the monitor i reiceive this:

Attempting to get an IP address using DHCP:
My address:192.168.1.3
connected...
ARDUINO: forming HTTP request message
ARDUINO: HTTP message sent
ARDUINO: HTTP message received
ARDUINO: printing received headers and script response...

HTTP/1.0 400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>

Why don't work?

char server[] = "arduinoalter.altervista.org/NuovoFile.php";

That is NOT a server. The server is "arduinoalter.altervista.org".

        client.print("GET http://arduinoalter.altervista.org/NuovoFile.php?user=12");

The page that you want does not include a protocol or the server name.

        client.print("GET NuovoFile.php?user=12");

PaulS:

char server[] = "arduinoalter.altervista.org/NuovoFile.php";

That is NOT a server. The server is "arduinoalter.altervista.org".

        client.print("GET http://arduinoalter.altervista.org/NuovoFile.php?user=12");

The page that you want does not include a protocol or the server name.

        client.print("GET NuovoFile.php?user=12");

Now i have this:

Attempting to get an IP address using DHCP:
My address:192.168.1.3
connected...
ARDUINO: forming HTTP request message
ARDUINO: HTTP message sent
ARDUINO: HTTP message received
ARDUINO: printing received headers and script response...

HTTP/1.1 400 Bad Request
Date: Thu, 22 Sep 2016 14:09:18 GMT
Server: Apache
Content-Length: 268
Connection: close
Content-Type: text/html; charset=iso-8859-1

<html><title>Bad request</title><head></head><body><p>Anomalia nella richiesta al sito, se il problema persiste <b>cancella i cookie</b>, <a href='https://support.google.com/accounts/answer/32050?hl=it' target='_blank'>maggiori informazioni</a></li></ul></body></html>

why?

why?

Because there is something (else) wrong with the code you didn't post after modifying.

PaulS:
Because there is something (else) wrong with the code you didn't post after modifying.

This is code:

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

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 
//byte mac[] =   {0xf0, 0x1f, 0xaf, 0x33, 0x62, 0x2f };
 
IPAddress ip(192,168,1,101);
 

EthernetClient client;
 
char server[] = "arduinoalter.altervista.org";
 

 
void setup()
{
  Serial.begin(9600);
 
  // attempt a DHCP connection:
  Serial.println("Attempting to get an IP address using DHCP:");
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println("failed to get an IP address using DHCP, trying manually");
    Ethernet.begin(mac, ip);
  }
 
  Serial.print("My address:");
  Serial.println(Ethernet.localIP());
}
 
 
void loop()
{
    // connect to the server
    if (client.connect(server, 80))
    {
        // print to serial monitor
        Serial.println("connected...");
        Serial.println("ARDUINO: forming HTTP request message");
 
        // send data the server through GET request
        client.print("GET NuovoFile.php?user=12");
        client.println(" HTTP/1.1");
        client.print("HOST: ");
        client.println(server);
        client.println();
 
        Serial.println("ARDUINO: HTTP message sent");        
 
        // give server some time to receive and store data
        // before asking for response from it
        delay(1000);
 
        // get the response from the page and print it to serial port
        // to ascertain that data was received properly
        if(client.available())
        {
            Serial.println("ARDUINO: HTTP message received");
            Serial.println("ARDUINO: printing received headers and script response...\n");
 
            while(client.available())
            {
                char c = client.read();
                Serial.print(c);
            }
        }
        else
        {
            Serial.println("ARDUINO: no response received / no response received in time");
        }
 
        client.stop();
    }
    // do nothing forever after:
    while(true);
}

this is php of page:

<?php
$_SESSION['username'] = $_GET['user'];
$comando = $_SESSION['username'];
$servername = "localhost";
$username = "prova";
$password = "";
$dbname = "my_prova";

$conn = new mysqli($servername, $username, $password, $dbname);


if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT Uno FROM Arduino";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$val = $row['Uno'];

$sql = "UPDATE Arduino SET Uno = ".$comando." WHERE Uno = ".$val." ";



mysqli_close($conn);
?>

Why don't work?

Edit
I have found error the error is here:
client.print("GET NuovoFile.php?user=12");
I haven't put / now is:
client.print("GET /NuovoFile.php?user=12");

1 If i want read/set value from/to input text, what i do?
2 If i want send comand to click button, what i do?
3 If i want send data with post request, what i do?

1 If i want read/set value from/to input text, what i do?

What input text? Where is the text input?

2 If i want send comand to click button, what i do?

Send what command to click a button, from where, to where?

3 If i want send data with post request, what i do?

Use a POST request. The data goes after a blank line after all the headers. But why? Is the data really that private?

PaulS:
What input text? Where is the text input?

Suppose i have page php with:

If i want read value or i want write in to value from arduino It is possible or not?

PaulS:
Send what command to click a button, from where, to where?

Suppose i have:

Can i send command click from arduino to button "prova"?

I don't see the relation between the page containing a form and the fact that it is a php script.

The form has a submit button, if it is to do anything with the input text field data. In general, that submit button sends another GET request to the same server that generated the form. So, if the Arduino is not the server, it is going to require some creativity on your part to make the submit button send the GET request to some other server (the Arduino), with the text field's content as part of the request.

Can i send command click from arduino to button "prova"?

No, the Arduino can not click a button. A button is a graphical representation in a browser, which is a client. One client (the Arduino) can not interact with another client (the browser) running on another computer.

Clients can interact only with a server, which, in general, promptly forgets about clients when it is done servicing their requests. So, it would be very difficult to make a client (the Arduino) send a request to a server, and have that server send something to another client (the browser).

but i want send two post:

Why? Why not make GET requests? They are far simpler.

The above is an old issue but look at the example code in ArduinoJson.h
refer to arduinojson.org

Enjoy