Posting Arduino data via ethernet to PHP server problems I am currently having difficulties sending data from an Arduino using an ethernet shield to a PHP database in MySQL. My problem is that it appears that the server is receiving the data as there is a time stamp when I send it from the Arduino however, the other values it is receiving are incorrect (see images below). The server says the values of "data", and "serial_number" are 0 but they are supposed to be 10 and 24. Along with that the Arduino is saying that the data has been sent successfully. My code for both the server and the Arduino is listed below. Any ideas on how to fix this or what is going on are much appreciated.



Arduino Code:

#include &lt;SPI.h&gt;
#include &lt;Ethernet.h&gt;

byte mac[] = { 0x00, 0xAB, 0xBA, 0xBC, 0xDD, 0x02 };
EthernetClient client;
String data;
int t;
int h;

void setup() {
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
  }

  Serial.println("still working here");


}


void loop() {
t = 10;
h = 24;

data = "temp1=";

data.concat(t);

data.concat("&amp;hum1=");

data.concat(h);


  if (client.connect("www.smartwater.x10host.com",80)) {
    Serial.println(data);
    client.print("POST /add.php HTTP/1.1\n");
    client.print("Host: www.smartwater.x10host.com\n");
    client.print("Connection: close\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(data.length());
    client.print("\n\n");
    client.print(data);
    Serial.println("Successfull");


  }

  if (client.connected()) {
    client.stop();
  }

  delay(20000);
}


add.php (Server Code)

&lt;?php
    include("connect.php");

    $link=Connection();

    $temp1=$_POST["data"];
    $hum1=$_POST["serial_number"];

    $query = "INSERT INTO `Main` (`data`, `serial_number`) 
        VALUES ('".$temp1."','".$hum1."')"; 

    mysql_query($query,$link);
    mysql_close($link);

    header("Location: index.php");
?&gt;


connect.php (Server Code)

&lt;?php

    function Connection(){
        $server="localhost";
        $user="smartwat_arduino";
        $pass="*****";
        $db="smartwat_Main";

        $connection = mysql_connect($server, $user, $pass);

        if (!$connection) {
            die('MySQL ERROR: ' . mysql_error());
        }

        mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );

        return $connection;
    }
?&gt;


index.php (Server Code)

&lt;?php

    include("connect.php");     

    $link=Connection();

    $result=mysql_query("SELECT * FROM `Main` ORDER BY `timeStamp` DESC",$link);
?&gt;

&lt;html&gt;
   &lt;head&gt;
      &lt;title&gt;Data&lt;/title&gt;
   &lt;/head&gt;
&lt;body&gt;
   &lt;h1&gt;Stuff&lt;/h1&gt;

   &lt;table border="1" cellspacing="1" cellpadding="1"&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;Timestamp&amp;nbsp;&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;Data&amp;nbsp;&lt;/td&gt;
            &lt;td&gt;&amp;nbsp;Serial Number&amp;nbsp;&lt;/td&gt;

        &lt;/tr&gt;

      &lt;?php 
          if($result!==FALSE){
             while($row = mysql_fetch_array($result)) {
                printf("&lt;tr&gt;&lt;td&gt; &amp;nbsp;%s &lt;/td&gt;&lt;td&gt; &amp;nbsp;%s&amp;nbsp; &lt;/td&gt;&lt;td&gt; &amp;nbsp;%s&amp;nbsp; &lt;/td&gt;&lt;/tr&gt;", 
                   $row["timeStamp"], $row["data"], $row["serial_number"]);
             }
             mysql_free_result($result);
             mysql_close();
          }
      ?&gt;

   &lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
In your Arduino code, the function call that send the real data within the HTTP-POST call, is this:

[...]
client.print(data);
[...]


When executed, the content of the data variable is sent to the server.

Supposing data is a String object then data.concat() is this function, allowing "... String, string, char, byte, int, unsigned int, long, unsigned long, float, double..." as argument.

So, after the execution, data should contain:

temp1=10&amp;hum1=24

and such content is exactly what is passed, via POST to the /add.php script.

Basically, you're passing two variables, called "temp1" and "hum1". Please keep note of those variable names!

Now let's switch the the PHP script, where you have:

[...]
$temp1=$_POST["data"];
$hum1=$_POST["serial_number"];
[...]


Above two statements, asks PHP to retrieve, via the $_POST function, the content of the two variables data and serial_number.

As such variables are undefined (the variables you passed were temp1 and hum1), PHP consider them like 0 and, as such, assign 0 to $temp1 and $hum1.

I bet that to solve your problem you only need to change above PHP with:

[...]
$temp1=$_POST["temp1"];
$hum1=$_POST["hum1"];
[...]


BTW: please note that what is inside the $_POST call is totally unrelated with the names of the variables you have on the left of the = sign: they are really different things!