send GET PHP ethernet

want to ask for help
i have problem when sending value from arduino into database using GET. when sent database response in received is failed send value. following its arduino source code:

#include <SPI.h>
#include <Ethernet_STM.h>


#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
;
#else
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
#endif  

char server[] = "192.168.0.99";    

IPAddress ip(192,168,0,45);

EthernetClient client;

void setup() {

  pinMode(PC0,INPUT);    //input
  Serial.begin(9600);
  while(!Serial){
    ;
  }

#if defined(WIZ550io_WITH_MACADDRESS)
  if (Ethernet.begin() == 0) {
#else
  if (Ethernet.begin(mac) == 0) {
#endif  
    Serial.println("Failed to configure Ethernet using DHCP"); 

#if defined(WIZ550io_WITH_MACADDRESS)
    Ethernet.begin(ip);
#else
    Ethernet.begin(mac, ip);
#endif  
  }
ConnectAndRead();
  }
  
void ConnectAndRead(){ 
  delay(5000); 
  int value = analogRead(PC0);
 
  Serial.println("connecting...");

    if (client.connect(server, 80)) {
    Serial.println("connected");
    
    // Make an HTTP request:
    client.println("GET /coba_ethernet/insert.php? HTTP/1.0");
    client.println("");
    client.println("value=");
    client.print(value);
    client.println("Host: 192.168.0.99");
    client.println("Connection: close");
    client.println();
    
    Serial.println("");
    Serial.print("Value :");
    Serial.println(value);
    Serial.println("");
    
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
    Serial.println("");
  }
}

void loop()
{
   if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    Serial.println("===========================================================");
    Serial.println("");
    client.stop();
    ConnectAndRead();

    delay(1000);
  }
}

and my php source

<?php
  if (!empty($_GET['value']))
  {
    $value = $_GET['value'];
 
    $con = mysqli_connect("192.168.0.99","root","123456789","arduino") or die("Gagal koneksi ke MySQL");
    mysqli_query($con,"INSERT INTO tes(value) VALUES ('$value')") or die ("Gagal insert data");
    mysqli_close($con);
    echo "OK  ";     
  }
  else
    echo "Fail to send";  
?>

this result from arduino compile/upload

connecting...
connected

Value :2570

HTTP/1.1 200 OK
Date: Tue, 10 Jul 2018 02:50:18 GMT
Server: Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
X-Powered-By: PHP/5.6.30
Content-Length: 12
Connection: close
Content-Type: text/html; charset=UTF-8

Fail to Send
disconnecting.
    client.println("GET /coba_ethernet/insert.php? HTTP/1.0");
    client.println("");
    client.println("value=");
    client.print(value);

The format of a GET statement is

GET path/script?name1=value1 [&name2=value2…] HTTP/1.n.

The name = value pair(s) do NOT follow the HTTP bit, as you are doing.
There are NO carriage returns or line feeds before the last of the values.

Try:

    client.print("GET /coba_ethernet/insert.php?");
    client.print("value=");
    client.print(value);
    client.println(" HTTP/1.0");

The Host record is needed only if using HTTP/1.1, not when using 1.0.

 client.print("GET /coba_ethernet/insert.php?");
    client.print("value=");
    client.print(value);
    client.println(" HTTP/1.0");

thank you for your response and answer

I've tried the code above and I'm very happy ahirnya can be solved my problem. but the value that goes into database is not suitable. on the back there is an HTTP / 1 letter, though I'm very grateful. almost 2 weeks I'm having trouble

these results are entered into in my database

4067HTTP/1 4058HTTP/1 4051HTTP/1 etc

4067 is value sensor from arduino HTTP/1 i don't know

this is the result of serial monitor

connecting...
connected
Value :4044

OK
disconnecting.
===========================================================

connecting...
connected
Value :4044

OK
disconnecting.
===========================================================

Before you do anything else, fix your PHP code. Your code is vulnerable to SQL injection attacks.

Don't use the mysqli_* functions, use PDO instead, and use prepared statements. Never insert raw user input into SQL queries.

Pieter

thank you feedback and suggestions I will try it

I've tried the code above and I'm very happy ahirnya can be solved

I have no idea what that means.

Post your COMPLETE code every time. You are not charged for the amount of code you post.

these results are entered into in my database

4067HTTP/1

That LOOKS like you do not have a space between the value and the "HTTP/1.0" bit.

PaulS:
I have no idea what that means.

Post your COMPLETE code every time. You are not charged for the amount of code you post.
That LOOKS like you do not have a space between the value and the “HTTP/1.0” bit.

sorry about that :slight_smile:

this code has been modified

#include <SPI.h>
#include <Ethernet_STM.h>


#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
;
#else
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
#endif  

char server[] = "192.168.0.99";    

IPAddress ip(192,168,0,45);

EthernetClient client;

void setup() {

  pinMode(PC0,INPUT);
  Serial.begin(9600);
  while(!Serial){
    ;
  }

#if defined(WIZ550io_WITH_MACADDRESS)
  if (Ethernet.begin() == 0) {
#else
  if (Ethernet.begin(mac) == 0) {
#endif  
    Serial.println("Failed to configure Ethernet using DHCP"); 

#if defined(WIZ550io_WITH_MACADDRESS)
    Ethernet.begin(ip);
#else
    Ethernet.begin(mac, ip);
#endif  
  }
//ConnectAndRead();
  }
//}
  
void ConnectAndRead(){ 
  delay(5000); 
  int value = analogRead(PC0);
 
  Serial.println("connecting...");

    if (client.connect(server, 80)) {
    Serial.println("connected");
    
    // Make an HTTP request:
    client.print("GET /coba_ethernet/insert.php?"); 
    client.print("value=");
    client.print(value);
    client.println("HTTP/1.0");
   // client.print();
    client.println("Host: 192.168.0.99");
    client.println("Connection: close");
      
    Serial.print("Value :");
    Serial.println(value);
    Serial.println("");
    
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
    Serial.println("");
  }
 }

void loop()
{
  
//
   if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    Serial.println("===========================================================");
    Serial.println("");
    client.stop();
    ConnectAndRead();

    delay(1000);
  }
}

and this result from serial monitor

connecting...
connected
Value :4046

OK
disconnecting.
===========================================================

connecting...
connected
Value :4058

OK
disconnecting.
===========================================================

connecting...
connected
Value :4036

OK
disconnecting.
===========================================================

connecting...
connected
Value :4041

OK
disconnecting.
===========================================================

That LOOKS like you do not have a space between the value and the "HTTP/1.0" bit.

thanks paulS for the suggestion, it's solved :)

I changed print to println at value

client.print("value=");
    client.print(value);

to

client.print("value=");
    client.println(value);

thank you all for helping

No, that would violate the HTTP standard. These protocols aren't just trial and error. Read the reference or the RFC and follow the format specified. You cannot just insert some line endings and hope for the best.

PieterP: No, that would violate the HTTP standard. These protocols aren't just trial and error. Read the reference or the RFC and follow the format specified. You cannot just insert some line endings and hope for the best.

ok. but actually I am still a beginner I just looking for a solution. so sorry if I violate the rules of the HTTP protocol and I do not mean to violate the rules Maybe in my future I still have much to learn and try.

    client.print("GET /coba_ethernet/insert.php?");
    client.print("value=");
    client.print(value);
    client.println("HTTP/1.0");

MY code had a space before the H. You removed it, jamming the HTTP part up against the value. PUT THE SPACE BACK!

kabayan: ok. but actually I am still a beginner I just looking for a solution. so sorry if I violate the rules of the HTTP protocol and I do not mean to violate the rules Maybe in my future I still have much to learn and try.

It doesn't matter if you're a beginner or not. The rules are there to help you. Following the specified format is not rocket science.

If you send a letter without specifying a correct address, the postal service cannot deliver your letter. Period. The same goes for the HTTP protocol (and any other protocol).