Probleming sending data from ardiuno uno to MYSQL USING EHERNET Sheild

HI!

i am using soil moisture sensor and i want the value which are display on serial monitor must me store in database but i failed and i am new in ardiuno programming

I UESD:

  1. ARDIUNO UNO .
  2. ETHERENET SHEILD
  3. SOIL MOISTURE SENSOR

DATABASE
MYSQL (XAMPP) .

CAN U HELP ME
ARDIUNO CODE

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


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1,  6); //Enter the IP of ethernet shield
char server[] = "192, 168, 1,5" ; //Enter the IPv4 address
EthernetClient client;
void setup() {
Ethernet.begin(mac, ip);
Serial.begin(9600); //setting the baud rate at 9600
Serial.println(Ethernet.localIP());
}

void loop() {
int soil_moisture = analogRead(A0);

Serial.print(soil_moisture);

 if (client.connect(server, 8080)) { //Connecting at the IP address and port we saved before
Serial.println("connected");
client.print("GET /soil_moisture/data1.php? "); //Connecting and Sending values to database
client.print("soil");
client.print(soil_moisture);
client.print("HTTP/1.1");
//client.print(" ");
client.stop(); //Closing the connection

//printing the value on the serial monitor
Serial.print("soil=");
Serial.println(soil_moisture);
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
delay(10000);
}
Connection1.php

<?php
$username = "soil_moisture";
$pass = "123";
$host = "localhost";
$db_name = "soil_moisture";
$con = mysqli_connect ($host, $username, $pass);
$db = mysqli_select_db ( $con, $db_name );
?>
data1.php

<?php
include ('connection1.php');
$sql_insert = "INSERT INTO soil_moisture.data (soil_moisture) VALUES ('".$_GET["soil_moisture"]."')";

if(mysqli_query($con,$sql_insert))
{
echo "Done";
mysqli_close($con);
}
else
{
echo "error is ".mysqli_error($con );
}
?>
display.php

<?php
$url=$_SERVER['REQUEST_URI'];
header("Refresh: 5; URL=$url"); // Refresh the webpage every 5 seconds
?>
<html>
<head>
<title>Arduino soil moisture Database</title>
<style type="text/css">
.table_titles {
padding-right: 20px;
padding-left: 20px;
color: #000;
}
.table_titles {
color: #FFF;
background-color: #0000FF;
}
table {
border: 2px solid #333;
}
body { font-family: "Trebuchet MS", Courier; }
</style>
</head>
<body>
<h1>Arduino Data Logging to Database</h1>
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="table_titles">ID</td>
<td class="table_titles">Date and Time</td>
<td class="table_titles">soil_moisture</td>
</tr>
<?php
include('connection1.php');
$result = mysqli_query($con,'SELECT * FROM data ORDER BY id DESC');
// Process every record
$oddrow = true;
while($row = mysqli_fetch_array($result))
{
if ($oddrow)
{
$css_class=' class="table_cells_odd"';
}
else
{
$css_class=' class="table_cells_even"';
}
$oddrow = !$oddrow; 
echo "<tr>";
echo "<td '.$css_class.'>" . $row['id'] . "</td>";
echo "<td '.$css_class.'>" . $row['event'] . "</td>";
echo "<td '.$css_class.'>" . $row['soil_moisture'] . "</td>";
echo "</tr>"; 
}
 
// Close the connection
mysqli_close($con);
?>
</table>
</body>
</html>

You are not sending any data to your HTTP endpoint. You are also using the GET method. I would try using the PUT method and sending the data along to that endpoint. While the GET method may still work depending on what your endpoint will allow, the most important thing is to send the data.

client.print("GET /soil_moisture/data1.php? "); //Connecting and Sending values to database

This is not an Arduino problem it is a REST problem with the HTTP request.

I would first try testing on your endpoint. Get an app to send HTTP requests or just type your URI into a web browser. Make sure you are including your data parameters in the URI (ex: www.example.com/endpoint.php?soil_moisture=65). In your PHP code $_GET[‘var’] are the things after the question mark.

sql_insert = "INSERT INTO soil_moisture.data (soil_moisture) VALUES ('"._GET[“soil_moisture”]."’)";

On the Arduino side of things, you then just need to do some string manipulation to create the correct URI.

Sorry, my last post was inaccurate. Your specified GET request URI is not formed correctly.

client.print("GET /soil_moisture/data1.php? "); //Connecting and Sending values to database
client.print("soil");
client.print(soil_moisture);

There is no equals symbol ("=") in your URI. (ex: www.example.com/endpoint.php?var=val)

I would still follow the steps of testing your endpoint separately from your Arduino.