save data temp and level from arduino to PC via ethernet-php-mysql

from referensi http://www.instructables.com/id/Save-data-of-temperature-and-humidity-on-MySQL-wit/
and http://forum.arduino.cc/index.php/topic,124289.0.html

i want to make arduino can send data temp and water level of tank via ethernet.
in this project i use:
PC : OS Windows; appliication Xampp
Arduino : Promini 328 (while flashing i use lib Uno);port A0 and A1 (never converted)

in this project make 3 file php : add.php, conec.php, and insertareg.php.
File add.php :

<?php
   include("conec.php");
   $link=Conection();
$Sql="insert into ardulevel (temp,level)  values ('".$_GET["temp"]."', '".$_GET["level"]."')";
   mysql_query($Sql,$link);
   header("Location: insertareg.php");
?>

file conec.php :

<?php
function Conection(){
   if (!($link=mysql_connect("localhost","root","")))  {
      exit();
   }
   if (!mysql_select_db("arduino",$link)){
      exit();
   }
   return $link;
}
?>

file insertareg.php :

<html>
<head>
   <title>Data Sensor</title>
</head>
<body>
<h1>Data dari sensor temperature and level</h1>
<form action="add.php" method="get">
<TABLE>
<tr>
   <td>Temperature 1</td>
   <td><input type="text" name="temp" size="20" maxlength="30"></td>
</tr>
<tr>
   <td>Level 1</td>
   <td><input type="text" name="level" size="20" maxlength="30"></td>
</tr>
</TABLE>
<input type="submit" name="accion" value="Masukkan">
</FORM>
<hr>
<?php
   include("conec.php");
   $link=Conection();
   $result=mysql_query("select * from ardulevel order by id desc",$link);
?>
<table border="1" cellspacing="1" cellpadding="1">
      <tr>
         <td>&nbsp;Waktu 1&nbsp;</td>
         <td>&nbsp;Temperature 1&nbsp;</td>
         <td>&nbsp;Level 1&nbsp;</td>
       </tr>
<?php
   while($row = mysql_fetch_array($result)) {
/*printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s&nbsp; </td></tr>", $row["waktu"], $row["temp"], $row["level"]);*/
printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s </td><td> &nbsp;%s </td></tr>", $row["waktu"], $row["temp"], $row["level"]);
   }
   mysql_free_result($result);
?>
</table>
</body>
</html>

and the sketch of arduino :

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 3, 2); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

String HTTP_req;          // stores the HTTP request
boolean LED_status = 0;   // state of LED, off by default

int tempValue = 0;
int levelValue = 0;



void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for diagnostics
                    
}

void loop()
{
 

EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                HTTP_req += c;  // save the HTTP request 1 char at a time
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    tempValue = analogRead(A0);
                    levelValue = analogRead(A1);
                    Serial.println(tempValue);
                    Serial.println(levelValue);
                    client.print( "GET /ard/add.php?"); // php??
                    client.print("temp=");
                    client.print(tempValue);
                    client.print("&&");
                    client.print("level=");
                    client.print(levelValue);
                    client.println( " HTTP/1.1");
                    client.println( "Host: localhost" );//ur web server
                    client.println( "Content-Type: application/x-www-form-urlencoded" );
                    client.println( "Connection: close" );
                    client.println();
                    client.println();
                    client.stop();
                    
                    ///
       
                    Serial.print(HTTP_req);
                    HTTP_req = "";    // finished with request, empty string
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

I try to add this address manually in the tab firefox :
localhost/ard/add.php?temp=28&&level=207
and the result is data can be inserted in table (update table),and then the address view the ‘insertareg.php’ like this ‘http://localhost/ard/insertareg.php’. look at this pic:

But if I just give the address http://192.168.3.2/ , the result is :

The problem is , how to make the address of http is automatically following the realtime data temp and level? In this case, if I input ‘192.168.3.2’ on address tab ,then arduino can send the real time data A0 and A1,may be per 5 second, to make address :
localhost/ard/add.php?temp=x&&level=y.
where, x and y in here data temp and level.
Because I think in the sketch of my arduino can’t run this proses. Thx a lot for your help…

soryy for my english,cos im indonesian…:slight_smile:

You are using server code on the Arduino. It should be a client. The php server is the server in your transaction, not the Arduino.

ow.. oke i want to try to cange the source code,thx for your suggest,, :)

i have changed my sketch, where arduino as a client. like this :

/*
  Web client
 
 
 */

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.xxxx.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(x,xx,xx);
int tempValue;// = analogRead(A0);
    int levelValue;// = analogRead(A1);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
 
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
   
   tempValue = analogRead(A0);
    levelValue = analogRead(A1);
    Serial.println(tempValue);
    Serial.println(levelValue);
    client.print( "GET /add.php?"); // php??
   client.print("temp=");
   client.print(tempValue);
   client.print("&&");
   client.print("level=");
   client.print(levelValue);
   client.println( " HTTP/1.1");
   client.println( "Host: www.xxx.com" );//ur web server
   client.println( "Content-Type: application/x-www-form-urlencoded" );
   client.println( "Connection: close" );
    client.println();
   
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }

 
}

void loop()
{
 
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}

and the result is succes for update table mysql and showed in website, BUT the respon in serial monitor arduino just calculate one action. look at the pic.

according to your post at http://playground.arduino.cc/Code/WebClient
i make the new sketch for webclient repeating, like this:

/*
  Repeating Web client
 
 */

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

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192,168,x,x);
int tempValue;// = analogRead(A0);
    int levelValue;// = analogRead(A1);

// fill in your Domain Name Server address here:
//IPAddress myDns(1,1,1,1);

// initialize the library instance:
EthernetClient client;

char server[] = "www.xxxx.com";

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 60*1000;  // delay between updates, in milliseconds

void setup() {
  // start serial port:
  Serial.begin(9600);
  // give the ethernet module time to boot up:
  delay(1000);
  // start the Ethernet connection using a fixed IP address and DNS server:
  //Ethernet.begin(mac, ip, myDns);
  Ethernet.begin(mac, ip);
  // print the Ethernet board/shield's IP address:
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
}

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 = client.read();
    Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    httpRequest();
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}

// this method makes a HTTP connection to the server:
void httpRequest() {
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
   
    tempValue = analogRead(A0);
    levelValue = analogRead(A1);
    Serial.println(tempValue);
    Serial.println(levelValue);
    client.print( "GET /add.php?"); // php??
   client.print("temp=");
   client.print(tempValue);
   client.print("&&");
   client.print("level=");
   client.print(levelValue);
   client.println( " HTTP/1.1");
   client.println( "Host: www.xxxx.com" );//ur web server
   client.println( "Content-Type: application/x-www-form-urlencoded" );
   client.println( "Connection: close" );
   
    client.println();

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

and the respon just like this :

hope your help master… thxx a lot…

fixduino :
OS Win7
arduino : Xboard V2 wiz5100

That sketch doesn't look anything like the sketch in the playground. Use the GET method example. It is designed to pass parameters to a PHP-MySQL server. Here is the code section that you modify to pass your stuff to the server. Use the sprintf that is commented out and replace the variable with your stuff. It works with my LAMP servers.

    // Modify next line to load different page
    // or pass values to server
    sprintf(pageAdd,"/",totalCount);

    // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

im sorry, that sketch is from example arduino software ‘webclient’. and now i have tried ur sketch with a litle change.
like this :

/*
   Web client sketch for IDE v1.0.1 and w5100/w5200
   Uses GET method.
   Posted October 2012 by SurferTim
   Last modified September 15, 2013
*/

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

// this must be unique
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// change to your network settings
IPAddress ip(192,168,3,9);
IPAddress gateway(192, 168, 3, 1);
IPAddress subnet(255, 255, 255, 0);

// change to your server
IPAddress server(31,xx,xx,23); // Google 31.170.162.23

//Change to your domain name for virtual servers
char serverName[] = "www.fixduino.comeze.com";
// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";

// change to your server's port
int serverPort = 80;

EthernetClient client;
//int totalCount = 0;
int tempValue = 0;
int levelValue=0;

char pageAdd[64];

// set this to the number of milliseconds delay
// this is 30 seconds
#define delayMillis 30000UL

unsigned long thisMillis = 0;
unsigned long lastMillis = 0;

void setup() {
  Serial.begin(9600);

  // disable SD SPI
//  pinMode(4,OUTPUT);
 // digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println(F("Starting ethernet..."));
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  // else Serial.println(F("ok"));
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("Ready"));
}

void loop()
{
  thisMillis = millis();

  if(thisMillis - lastMillis > delayMillis)
  {
    lastMillis = thisMillis;

    // Modify next line to load different page
    // or pass values to server
    //sprintf(pageAdd,"/",totalCount);
     sprintf(pageAdd,"/add.php?temp=%u&&level=%u",tempValue,levelValue);

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    //totalCount++;
    
     tempValue=analogRead(A0);
    levelValue=analogRead(A1);   // Serial.println(totalCount,DEC);
   
   Serial.println(tempValue);
   Serial.println(levelValue);
  }    
}

byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();

  return 1;
}

and the respon is :

thx for help… and now i will try it for waterlevel sensor… do you have suggesttion the best sensor? :slight_smile:

Have you looked up what a 302 return code means?

http://en.wikipedia.org/wiki/HTTP_302

owww.. that means the web response failed?? :(

fixduino: owww.. that means the web response failed??

No. It means you are being redirected to a different page. You requested /add.php, and the server is redirecting you to /insertareg.php.

owwke,,copyed for that. so,that are more eficient if i not redirecting to insertareg.php? are this case will disturbing the process of data (temp and level) update?

in other case,according to your post in http://forum.arduino.cc/index.php?topic=124289.60 , i have modified my sketch :

void loop()
{
  thisMillis = millis();

  if(thisMillis - lastMillis > delayMillis)
  {
    lastMillis = thisMillis;

    // Modify next line to load different page
    // or pass values to server
    //sprintf(pageAdd,"/",totalCount);
    tempValue=analogRead(A0);
    levelValue=analogRead(A2);   // Serial.println(totalCount,DEC);
   // tempValue = (5.0 * tempValue * 100.0)/1024.0;  //convert the analog data to temperature
    tempValue = (tempValue/1023.0)*100.0;  //convert the analog data to temperature 
    levelValue = (levelValue/1023.0)*500.0;  //convert the analog data to temperature
    
    char tempBuffer[8];
    char levelBuffer[8];    
    dtostrf(tempValue,3,1,tempBuffer); 
    dtostrf(levelValue,3,1,levelBuffer); 
    sprintf(pageAdd,"/add.php?temp=%s&&level=%s",tempBuffer,levelBuffer);
  
    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    //totalCount++;
    
    //Serial.println((byte)tempValue);             //send the data to the computer
    Serial.println(tempValue);             //send the data to the computer
    Serial.println(levelValue);             //send the data to the computer
  
    delay(5000);                           //wait one second before sending new data
 }    
}

in the serial monitor ,i think the data temp and level are corected,cause the resul is data float. ex: 10.3; 165.85

but why in the web just update data like integer, ex: 10 ; 165

pic : thx again for ur help ,,master...

The error (not really an error) is telling you to use /insertareg.php. not /add.php. It will not process that request until you use the correct page. And don't use the double ampersand.

// change this...
sprintf(pageAdd,"/add.php?temp=%s&&level=%s",tempBuffer,levelBuffer);
// ... to this:
sprintf(pageAdd,"/insertareg.php?temp=%s&level=%s",tempBuffer,levelBuffer);

i have change that line to my sketch… and data update in the table mysql is corect (float) .
and beside that for solve the problem 302respon, i combine the file add.php with insertareg.php to be one file . but the respon from serial monitor like this…

arduino view the html sourcecode,its oke but the data update not always correct…

file new insertareg.php :

<html>
<head>
<meta http-equiv="refresh" content="30">

   <title>Data Sensor</title>
 
</head>
<body>
<h1>Data dari sensor temperature and level</h1>
<h2>Update Terakhir</h2>
<TABLE>
<tr>
   <td>Temperatur</td>
   <td><input type="text" name="temp" size="20" maxlength="30" ></td>
</tr>
<tr>
   <td>Level</td>
   <td><input type="text" name="level" size="20" maxlength="30" ></td>
</tr>
</TABLE>
<input type="submit" name="accion" value="Masukkan">
</FORM>
<hr>
<?php
   

   include("conec.php");
   $link=Conection();
$Sql="insert into ardulevel (temp,level)  values ('".$_GET["temp"]."', '".$_GET["level"]."')";
   mysql_query($Sql,$link);

 $result=mysql_query("select * from ardulevel order by id desc",$link);


  
?>


<table border="1" cellspacing="1" cellpadding="1">
      <tr>
         <td>&nbsp;Waktu &nbsp;</td>
         <td>&nbsp;Temperatur (C) &nbsp;</td>
         <td>&nbsp;Level (cm) &nbsp;</td>
       </tr>
<?php
date_default_timezone_set('Asia/Jakarta');
   echo date("d-m-Y H:i:s");

   while($row = mysql_fetch_array($result)) {
/*printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s&nbsp; </td></tr>", $row["waktu"], $row["temp"], $row["level"]);*/
printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s </td><td> &nbsp;%s </td></tr>", $row["waktu"], $row["temp"], $row["level"]);
   }
   mysql_free_result($result);
?>
</table>
</body>
</html>

how to fix this…

Are all those requests yours? Since the Arduino does not recognize this, remove it from your php code.

<meta http-equiv="refresh" content="30">

I see your Arduino posting the correct data every 30 seconds, but the other entries are not 30 seconds apart. A web browser using that page would not send the parameters, and there would be blank entries when your php code gets those requests. You might want to evaluate the contents of the request for the temp and level parameters before inserting them into your MySQL table.

yes i have try it to delete that line code,,and the result data can be updated correctly,but how the other ways to refresh data in php but that updated still correctly?? can you make some condition code in php to solve this?? thxx... soorry im php beginner too..

Use isset in your php code to determine if the variables were sent by the client. Like this for the temp variable:

if(isset($_GET['temp'])) {
    // temp exists
}

i have edit insertareg.php like this :

<html>
<head>

   <title>Data Sensor</title>

</head>
<body>
<h1>Data dari sensor temperature and level</h1>
<h2>Update Terakhir</h2>
<TABLE>
<tr>
   <td>Temperatur</td>
   <td><input type="text" name="temp" size="20" maxlength="30" ></td>
</tr>
<tr>
   <td>Level</td>
   <td><input type="text" name="level" size="20" maxlength="30" ></td>
</tr>
</TABLE>
<input type="submit" name="accion" value="Masukkan">
</FORM>
<hr>
<?php


   include("conec.php");
   $link=Conection();

   if(isset($_GET['temp'])&&($_GET['level'])) {
    // temp exists
    date_default_timezone_set('Asia/Jakarta');
    $s = time ();
    $dayz =date("d-m-Y H:i:s",$s);

    $Sql="insert into ardulevel (waktu,temp,level)  values ( '".$dayz."','".$_GET["temp"]."', '".$_GET["level"]."')";
     mysql_query($Sql,$link);

    }
    else {

          $result=mysql_query("select * from ardulevel order by id desc",$link);
    }

?>


<table border="1" cellspacing="1" cellpadding="1">
      <tr>
         <td>&nbsp;Waktu &nbsp;</td>
         <td>&nbsp;Temperatur (C) &nbsp;</td>
         <td>&nbsp;Level (cm) &nbsp;</td>
       </tr>
<?php
date_default_timezone_set('Asia/Jakarta');
   echo date("d-m-Y H:i:s");

 //  UPDATE `ardulevel` SET `id`=[value-1],`waktu`=[value-2],`temp`=[value-3],`level`=[value-4] WHERE 1

   while($row = mysql_fetch_array($result)) {
/*printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s&nbsp; </td></tr>", $row["waktu"], $row["temp"], $row["level"]);*/
printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s </td><td> &nbsp;%s </td></tr>", $row["waktu"], $row["temp"], $row["level"]);
   }
   mysql_free_result($result);
?>
</table>
</body>
</html>

and i try to make example value for temp and level like this(i try with easyphp): localhost/ard/insertareg.php?temp=val1&val2,
data can update but any samething wrong like in the pid,any suggest? thxx master

If the variables are sent to the php script, then $result is undefined. You need to declare $result in the isset() section, or check for $result set the same way in the second part of your php script.

This is really a php question, and a bit out of scope for this forum.

oke thx for your suggest,and im sorry for my question.. i will try more in php..thx :)

localhost/ard/insertareg.php?temp=val1&val2,

And what equals val2?

@pauls : hai mr pauls,i have wrong connection in localhost, i dont know why may be the problem is ‘dhcp not ON’. cause i just connect arduino to the pc which that localhost i mean.
then, i try to make website where i set arduino as a client which can send data directly to the website.i can do that… i have question to you master: is any probably to communicate arduino with localhost ,so not must to connect internet.thx

@surfertrim : hai again master,i have solve the php code problem (for new system):

<?php
   date_default_timezone_set('Asia/Jakarta');
   echo date("d-m-Y H:i:s \r\n");

   include("conec.php");
   $link=Conection();

   if(isset($_GET['level'])and($_GET['press'])and ($_GET['stpump1'])and ($_GET['stpump2'])and ($_GET['stpump3'])and ($_GET['stpump4'])) {
    // level exists
    $s = time ();
    $dayz =date("d-m-Y H:i:s",$s);
    $level1=$_GET['level'];
    $press1=$_GET['press'];
    $statp1=$_GET['stpump1'];
    $statp2=$_GET['stpump2'];
    $statp3=$_GET['stpump3'];
    $statp4=$_GET['stpump4'];

     echo ("level=$level1 \r\n" );
     echo ("press=$press1 \r\n" );
     echo ("status=$statp1 \r\n" );
         echo ("status=$statp2 \r\n" );
         echo ("status=$statp3 \r\n" );
         echo ("status=$statp4 \r\n" );

         echo "\r\n";
    $Sql="insert into tblevel (waktu,time,level,press,stpump1,stpump2,stpump3,stpump4)  values ( '".$s."','".$dayz."','".$level1."', '".$press1."', '".$statp1."', '".$statp2."', '".$statp3."', '".$statp4."')";
     mysql_query($Sql,$link);
 //$Sql="insert into dblevel (waktu,level,press,status)  values ( '".$dayz."','".$_GET["level"]."', '".$_GET["press"]."', '".$_GET["status"]."')";

   }
    else {

          $result=mysql_query("select * from tblevel order by id desc",$link);
    }

?>

and now i have a litle adjus in my project,that is ‘system monitor level of firepump online’.the data must be send by arduino like this

http://xxx.com/insertareg.php?level=160&press=2.9&stpump1=ALARM&stpump2=OFF&stpump3=OFF&stpump4=OFF

the table of update data like in the pic :

this is my sketch :

/*
   sistem monitoring level kolam pemadam via website
   Posted January 16 by fixduino
   Last modified January 30, 2014
*/

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

// this must be unique
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// change to your network settings
IPAddress ip(192,168,3,x);
IPAddress gateway(192, 168, 3, 1);
IPAddress subnet(255, 255, 255, 0);

// change to your server
IPAddress server(31,xx,xx,xx);  

//Change to your domain name for virtual servers
char serverName[] = "www.xx.com";
// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";

// change to your server's port
int serverPort = 80;

EthernetClient client;
//int totalCount = 0;
float levelValue=0;
float pressValue = 0;
int stp1Value = 0;int stp2Value = 0;int stp3Value = 0;int stp4Value = 0;
String stat1;
String stat2;String stat3;String stat4;
char* myStrings[]={"ON", "OFF"}; //declare status pump

char pageAdd[128];

// set this to the number of milliseconds delay
// this is 30 seconds
#define delayMillis 30000UL

unsigned long thisMillis = 0;
unsigned long lastMillis = 0;

void setup() {
  Serial.begin(9600);

  // disable SD SPI
//  pinMode(4,OUTPUT);
 // digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println(F("Starting ethernet..."));
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  // else Serial.println(F("ok"));
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("Ready"));
}

void loop()
{
  thisMillis = millis();

  if(thisMillis - lastMillis > delayMillis)
  {
    lastMillis = thisMillis;

    // Modify next line to load different page
    // or pass values to server
    //sprintf(pageAdd,"/",totalCount);
    levelValue=analogRead(A0);
    pressValue=analogRead(A1);   // Serial.println(totalCount,DEC);
    stp1Value=analogRead(A2);  // status pompa1
    stp2Value=analogRead(A3);   //status pompa2
    stp3Value=analogRead(A4);    //status pompa3
    stp4Value=analogRead(A5);    //status pompa4
   // tempValue = (5.0 * tempValue * 100.0)/1024.0;  //convert the analog data to temperature
    //tempValue = (tempValue/1023.0)*100.0;  //convert the analog data to temperature 
    levelValue = (levelValue/1023.0)*200.0;  //convert the analog data tolevel .max 200cm
    pressValue = (pressValue/1023.0)*10.0;  //convert the analog data to press. max 10kg/cm2 
    if (stp1Value>0){
      stat1= myStrings[0]; //make status pump1 ON
    } else {
      stat1= myStrings[1]; //make status pump1 OFF
    }
    if (stp2Value>0){
      stat2= myStrings[0];
    } else {
      stat2= myStrings[1];
    }
    if (stp3Value>0){
      stat3= myStrings[0];
    } else {
      stat3= myStrings[1];
    }
    if (stp4Value>0){
      stat4= myStrings[0];
    } else {
      stat4= myStrings[1];
    }
    
    
    char levelBuffer[8];
    char pressBuffer[8];
    char stp1Buffer[8];
    char stp2Buffer[8];
    char stp3Buffer[8];
    char stp4Buffer[8];
    dtostrf(levelValue,3,1,levelBuffer); 
    dtostrf(pressValue,3,1,pressBuffer); 
    sprintf(stp1Buffer,"%s",stat1);  
    sprintf(stp2Buffer,"%s",stat1);
    sprintf(stp3Buffer,"%s",stat1);
    sprintf(stp4Buffer,"%s",stat1);
    
   // sprintf(pageAdd,"/insertareg.php?level=%s&press=%s",levelBuffer,pressBuffer);
   //sprintf(pageAdd,"/insertareg.php?level=%s&press=%s&stpump1=%s&stpump2=%s&stpump3=%s&stpump4=%s",levelBuffer,pressBuffer,stat1,stat2,stat3,stat4);
     sprintf(pageAdd,"/insertareg.php?level=%s&press=%s&stpump1=%s&stpump2=%s&stpump3=%s&stpump4=%s",levelBuffer,pressBuffer,stp1Buffer,stp2Buffer,stp3Buffer,stp4Buffer);

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    //totalCount++;
    
    //Serial.println((byte)tempValue);             //send the data to the computer
    Serial.println(levelValue);             //send the data to the computer
    Serial.println(pressValue);             //send the data to the computer
    Serial.println(stat1);             //
    delay(1000);                           //wait one second before sending new data
 }    
}

byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
          
    
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();

  return 1;
}

and now,my little problem is = send value status of pump (ON or OFF).i am still have no understand about char. thanks