Arduino Ethernet write to MYSQL using php issue

I have the following Arduino sketch that seems to be working fine

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

int bstate = 0;
String txData="";

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

IPAddress server(192,168,1,65);

void setup(){
delay(1000);
Ethernet.begin(mac);
Serial.begin(9600);

}

void loop(){
bstate++;
txData = (String(bstate));
EthernetClient client;
if(client.connect(server, 80)){
delay(100);
Serial.println("Connected to ego...");
Serial.println();

client.print("GET localhost/ego/WebContent/test.php?num=");
client.print(txData);
client.print(" HTTP/1.1");
client.println(" HOST: localhost");
client.println(" Connection: close");
client.println("");
Serial.println("data sent");
}
else{
Serial.println("Connection Failed.");
Serial.println();
}
delay(5000);
}

However, I am not seeing any changes reflected in the database.
Here is test.php:

<?php $connection = mysqli_connect("localhost", "root", ""); mysqli_select_db($connection, "ego"); $data = $_GET['num']; $sql = "INSERT INTO MY_TABLE(BUTTON_STATE) VALUES($data)"; mysqli_query($connection, $sql); ?>

Here is the Apache access.log:
192.168.1.92 - - [13/Mar/2014:21:23:49 -0700] "GET localhost/ego/WebContent/test.php?num=1 HTTP/1.1 HOST: localhost" 400 979 "-" "-"
192.168.1.92 - - [13/Mar/2014:21:23:54 -0700] "GET localhost/ego/WebContent/test.php?num=2 HTTP/1.1 HOST: localhost" 400 979 "-" "-"
192.168.1.92 - - [13/Mar/2014:21:23:59 -0700] "GET localhost/ego/WebContent/test.php?num=3 HTTP/1.1 HOST: localhost" 400 979 "-" "-"
192.168.1.92 - - [13/Mar/2014:21:24:04 -0700] "GET localhost/ego/WebContent/test.php?num=4 HTTP/1.1 HOST: localhost" 400 979 "-" "-"
192.168.1.92 - - [13/Mar/2014:21:24:09 -0700] "GET localhost/ego/WebContent/test.php?num=5 HTTP/1.1 HOST: localhost" 400 979 "-" "-"

I spent some time going over this post that describes a similar issue: [SOLVED] Arduino Ethernet write to MySQL $_GET issue PHP WAMP - Networking, Protocols, and Devices - Arduino Forum
But I still can't get it to work.

You might try the below. Note that localhost is 127.0.0.1 on a pc.

client.print("GET localhost/ego/WebContent/test.php?num=");
client.print(txData);
client.println(" HTTP/1.1");
client.println("HOST: localhost");
client.println("Connection: close");
client.println();

Note that localhost is 127.0.0.1 on a pc.

localhost is the name of the server instance running on the same hardware as the client request is made on, regardless of whether the client is running on a PC, on a mainframe, or on an Arduino.

You do NOT want to make a request to localhost from the Arduino. The server you are trying to talk to is NOT running on the Arduino.

Using a host of "localhost" is a moot point. You can use any hostname, valid or invalid -- it all depends on how the webserver is configured in its name-based virtualhosting. With that said, if you're using the name "localhost" then you're probably hitting the default virtualhost in your webserver configuration. You could just leave it out.

Obvious errors:

  1. zoomkat pointed out that you didn't println after " HTTP/1.1". You also need to make sure you're not including a space at the front of each line.
  2. Your URL should probably be prefixed with "/". I.e. **/**localhost/ego/WebContent/test.php. You're getting 404 errors presently and that means you're calling an invalid URL.