Unable to send data from arduino to phpMyAdmin database

Hi, everyone. I need to send data from sensors on Arduino to phpmyadmin database. I have managed to send over a single value to a one-column-database but I'm unable to send a set of three different values to a three-column-database.

So I decided to debug my Arduino code and send three pre-initialised values to the database. As it turns out, I'm not able to do that either. I'm able to see the values being displayed on the serial monitor but they are not being uploaded to the database. Please help me.

The Arduino sketch, the serial monitor data and the PHP code are mentioned below and I have attached a screenshot of the table structure from phpmyadmin.

Arduino sketch:

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(192,168,,);

char server[] = "192.168.**.";

char pid='A';
char pname='B';
char cat='C';

EthernetClient client;

void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
delay(5000);
}

void loop()
{
if (client.connect(server, 80))
{
Serial.println("Connection Established");

client.print("GET /abc.php?");

client.print("pid=");

client.print(pid);

client.print("&pname=");

client.print(pname);

client.print("&cat=");

client.print(cat);

client.stop();

Serial.println(pid);

Serial.println(pname);

Serial.println(cat);

pid+=3;

pname+=3;

cat+=3;
}

else
{
Serial.println("Connection failed\n");

client.stop();
}
delay(10000);
}


Serial monitor data:

Connection Established
A
B
C
Connection Established
D
E
F
Connection Established
G
H
I


PHP code:

<?php $dbusername = "manager"; $dbpassword = "managerstock"; $server = "localhost"; $dbconnect = mysqli_connect($server, $dbusername, $dbpassword); $dbselect = mysqli_select_db($dbconnect, "stock"); $pid = $_GET['pid']; $pname = $_GET['pname']; $cat = $_GET['cat']; $sql = "INSERT INTO stock.inventory (pid, pname, cat) VALUES ('$pid','$pname','$cat')"; mysqli_query($dbconnect, $sql); ?>

Please help me ???
There's nowhere left that I haven't looked and I'm still trying.

why aren't you using Example "WebClient"

I'm missing all the HTTP and HOST and Connection information in your sketch!

if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.1");
** client.println("Host: www.google.com");**
** client.println("Connection: close");**
** client.println();**
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}

I saw a video in which those HTTP and HOST connections weren't there. They said that those are unnecessary. Their sketch was still working. But I figured another way out. Anyway thanks for replying.

What did the response from the server say?

It was blank.

udbhav95:
It was blank.

That is because you are not waiting for a response. You send a request, then immediately close the connection. Try this:

   client.print(cat);

   // add this
   while(client.connected()) {
      while(client.available()) {
         char ch = client.read();
         Serial.write(ch);
      }
   }

   client.stop();

Edit: You also need to send a blank line after your request send

   client.println(cat);
   client.println();

Actually, it worked without this. Anyways thanks for replying.

udbhav95:
Actually, it worked without this. Anyways thanks for replying.

No problem. You can leave out the response read, but if something goes wrong in the future, it will be almost impossible to troubleshoot.

Yeah, it would. Hey, can you please help me out on this? Sending data from phpMyAdmin database to Arduino - Project Guidance - Arduino Forum

I posted a response, but I do not monitor that section of the forum. I stick mainly with the Networking section.