Arduino ethernet webclient php script and mysql

If so what is wrong with my code which stops me writing to the database?

The arduno is working just fine. The issue is on your server and what application you are using with apache to interpet what is sent and the manipulaton of your database. If the server is on a linux box, then you need to have some linux compatable application to perform the database operations when apache gets the incomming request. In the past I think Perl was often used as a CGI application. PHP might have a version for linux.