I want to write into my database which is located on my server. Select-Statements work totally fine, but I want to create a new entry in the table. I use the INSERT for this and did it this way:
Java Code (of App/Client):
//the year data to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", idNumber.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("name", nameText.getText().toString()));
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://olli130.myds.me/sqlcreate.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.i("Sent to Server", "name: " + nameText.getText().toString() + ", id: " + idNumber.getText().toString());
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
And the PHP Code:
<?php
include 'sqlcon.php';
$connection=mysql_connect($mysqlhost, $mysqluser, $mysqlpwd) or die
("Verbindungsversuch fehlgeschlagen");
mysql_select_db($mysqldb, $connection) or die("Konnte die Datenbank nicht
waehlen.");
$sql = "INSERT INTO Testtable (id, descr)
VALUES (".$_REQUEST['id']", '".$_REQUEST['name']"')";
mysql_query($sql) or die (mysql_error());
mysql_close($connection);
?>
Am i doing something badly wrong? Why is it not working?