Send data to MySQL (Arduino Uno, Eth shield W5100, IR obstacle sensor) [solved]

Thanks for your reply.

6v6gt:
OK. The PHP code works when you type a URL manually in a web browser. Something like:

http://192.168.0.121/arduino/getdata.php?sensor1=91&sensor2=92&sensor3=93

Yes. It works just fine when I'm doing that. I can see the value is store in the database.

I change my code like this, as what I understand from your reply:

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

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
byte ip[] = { 192, 168, 0, 127 };
byte server[] = { 192, 168, 0, 121 };

//Initialize the Ethernet server library
EthernetClient client;

int LED = 13; // Use the onboard Uno LED
int isSensePin = 7;  // This is our input pin
int isSensePin2 = 8;
int isSensePin3 = 9;
int sensor1 = HIGH;  // HIGH MEANS NO OBSTACLE
int sensor2 = HIGH;
int sensor3 = HIGH;

void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(isSensePin, INPUT);
  pinMode(isSensePin2, INPUT);
  pinMode(isSensePin3, INPUT);

  Serial.begin(9600);
  while (!Serial)
  {
    ;
  }
  if (Ethernet.begin(mac) == 0)
  {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }

  delay(1000);
  Serial.println("connecting...");

  if (client.connect(server, 80))
  {
    Serial.println("---connected---");

    client.println("GET /arduino/getdata.php?");
    client.println("Host: 192.168.0.121");
    client.println("Connection: close");
    client.println();
  }
  else
  {
    Serial.println("---connection failed---");
  }
}


void loop()
{
  sensor1 = digitalRead(isSensePin);
  sensor2 = digitalRead(isSensePin2);
  sensor3 = digitalRead(isSensePin3);

  if (client.connect(server, 80))
  {
    Serial.println("---connection ok---");

    client.print("GET /arduino/getdata.php?");
    client.print("sensor1 = ");
    client.print(sensor1);
    client.print("&sensor2 = ");
    client.print(sensor2);
    client.print("&sensor3 = ");
    client.print(sensor3);

    client.println("HTTP/1.1");
    client.println("Host: 192.168.0.121");
    client.println("Connection: close");
    client.println();

    Serial.print("sensor1 = ");
    Serial.println(sensor1);
    Serial.print("sensor2 = ");
    Serial.println(sensor2);
    Serial.print("sensor3 = ");
    Serial.println(sensor3);

    client.stop();
  }

  else
  {
    Serial.println("---connection failed---\n");
    client.stop();
  }

  delay (500);

  sensor1 = digitalRead(isSensePin);
  if (sensor1 == LOW)
  {
    Serial.println("Occupied1");
    digitalWrite(LED, HIGH);
  }
  else
  {
    Serial.println("Available1");
    digitalWrite(LED, LOW);
  }
  delay(1000);

  sensor2 = digitalRead(isSensePin2);
  if (sensor2 == LOW)
  {
    Serial.println("Occupied2");
    digitalWrite(LED, HIGH);
  }
  else
  {
    Serial.println("Available2");
    digitalWrite(LED, LOW);
  }
  delay(1000);

  sensor3 = digitalRead(isSensePin3);
  if (sensor3 == LOW)
  {
    Serial.println("Occupied3");
    digitalWrite(LED, HIGH);
  }
  else
  {
    Serial.println("Available3");
    digitalWrite(LED, LOW);
  }
  delay(1000);
}

and the output is like this:

connecting...
---connection failed---
---connection ok---
sensor1 = 0
sensor2 = 1
sensor3 = 1
Occupied1
Available2
Available3
---connection ok---
sensor1 = 1
sensor2 = 1
sensor3 = 1
Occupied1
Available2
Available3
---connection ok---
sensor1 = 0
sensor2 = 1
sensor3 = 1

It seems like the connection is failed at void setup()

6v6gt:
You are not using status.php in your Arduino code.

As what I understand, getdata.php is to store data to database, and status.php is to display the data from database. Are you saying that I need to change -client.print("GET /arduino/getdata.php?");- to this -client.print("GET /arduino/status.php?");- ?