Hi,
Okay, so I added in some code to my php file so it writes to a text file to see if the values are being received - they are not. The php file writes values when I manually run it in a browser.
Here is my updated arduino code:
if (client.connect(host, 80))
{
Serial.println("\nConnected to database...");
client.print("GET /send_data.php?latitude=");
Serial.print("GET /send_data.php?latitude=");
client.print(latitude);
Serial.print(latitude);
client.print("&longitude=");
Serial.print("&longitude=");
client.print(longitude);
Serial.print(longitude);
client.println("HTTP/1.1");
client.println("Host: 192.168.0.11"); // SERVER ADDRESS
client.println( "Content - Type : text/php" );
client.println("Connection: close");
client.println();
client.println();
PHP file:
<?php
//require("config.php");
$dbHost = "localhost";
$dbUsername = "root";
$dbPassword = '';
$dbName = "map1";
// Opens a connection to a MySQL server
$connection = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);
if (!$connection) {
die('Not connected : Ah shit ' . mysqli_error());
}
//Set the active MySQL database
$db_selected = mysqli_select_db($connection, $dbName );
if (!$db_selected) {
die ('Can\'t use db : ' . mysqli_error());
}
//$request = $_GET['request'];
//$sql = "INSTERT INTO request.request (request)
//VALUES ('$request', '$request', '$request', '$request', '$request')";
$latitude = $_GET['latitude'];
$longitude = $_GET['longitude'];
//TEST to see if values received.
$myfile = fopen("testfile.txt", "w");
fwrite($myfile,$latitude);
fwrite($myfile,"\n");
fwrite($myfile,$longitude);
fwrite($myfile,"\n");
fclose($myfile);
//INSERT into SQL database
$sql = "INSERT INTO markers (name, address, lat, lng, type)
VALUES ('GPSname', 'GPSaddress','$latitude','$longitude', 'GPStype')";
// VALUES ('GPS', 'GPS','".$GET["latitude"]."','".$_GET["longitude"]."', 'GPS');
//Checks to see if new record made
if (mysqli_query($connection, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "
" . mysqli_error($connection);
}
mysqli_close($connection);
?>
Thanks again for helping!