In my test i use PHP
to convert the json
string to insert it in the mysql
database.
This is how the php file looks like:
if (isset($_GET['data'])) { // Is er data binnengekomen, zoja voer dan de rest uit
$data = json_decode($_GET['data'], true);
$id = $data['id']; //Het personeelsnummer
$latitude = $data['latitude']; // De latitude (coordinaten)
$longitude = $data['longitude']; // De longitude (coordinaten)
$timestamp = $data['timestamp']; // De tijd
$result = mysql_query("SELECT * FROM locatie WHERE id='$id'"); //Kijken of het personeelsnummer al in de database staat of niet
if(mysql_num_rows($result)>0) //Hier wordt de functie uitgevoerd als het al in de database staat
{
$query = "Update locatie
SET longitude = '$longitude',
latitude = '$latitude',
timestamp = '$timestamp'
WHERE id = '$id'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "OK";
// Voer de $query(de Update Functie) uit
mysql_free_result($result);
} // Als het er in staat, Update alle waardes die voor het personeelsnummer gelden. Wordt dus geen geschiedenis opgeslagen
else //Hier wordt de functie uitgevoerd als het nog niet in de database staat
{
//Als het een nieuw nummer is
$query = sprintf("INSERT INTO locatie (id, longitude, latitude, timestamp) VALUES ('%s', '%s', '%s', '%s') ", mysql_real_escape_string($id) , mysql_real_escape_string($longitude), mysql_real_escape_string($latitude), mysql_real_escape_string($timestamp));} // Als het er nog niet instaat voeg dan het personeelsnummer in en de andere waardes.
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "OK";
// Voer de $query(de Insert Functie) uit
mysql_free_result($result);
}
This works perfectly fine, but the company requested that it should be in ASP.
But the point is, that im just bad at asp.
Here's my code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Naamloos document</title>
</head>
<body>
<%
Dim sConnection, objConn , objRS
sConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=Your_Mysql_DB; UID=mysql_username;PASSWORD=mysql_password; OPTION=3"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(sConnection)
If Request.Form("data") <> "" Then
Request.QueryString["id"]
Request.QueryString["longitude"]
Request.QueryString["latitude"]
Request.QueryString["timestamp"]
Set objRS = objConn.Execute("SELECT * FROM locatie WHERE id='id'")
If objRS <> "" Then
Set objRS = objConn.Execute("Update locatie
SET longitude = 'longitude',
latitude = 'latitude',
timestamp = 'timestamp'
WHERE id = 'id'")
Else
Set objRS = objConn.Execute("INSERT INTO locatie (id, longitude, latitude, timestamp) VALUES ('id', 'longitude', 'latitude', 'timestamp') ")
End If
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
</body>
</html>
I send this jsonstring:
2012-10-10 08:50:32.011 Appname[4049:c07] Post String =http://www.yourdomain.nl/locatie.asp?data=%7B%22id%22:%220612833397%22,%22longitude%22:%22-143.406417%22,%22latitude%22:%2232.785834%22,%22timestamp%22:%2210-10%2007:56%22%7D
EDIT
So my question is:
If the ASP works just as the PHP file. I dont know if i use the right methods to decode the json, if i use the right method if id=id in the database, if i use the right methos to parse it in the database