Hello to eveybody,
I'm buidling a robot that measures the available networks and send this information to a web server that I have also created in my local network, using Apache+PHP+MySQL. The problem is that when I send a simple POST message to test the system, the PHP I've programmed (addNewNetworks.php) does not receive the message or does not process it, I don't know where the problems is. I've searched for many samples, fórums, etc.., and to me it seems everything is ok, but the connection is not working at all.
The connection with the database is working as I can see the content by using another php file (index.php):
the code i'm using in my microprocessor to send the data is:
client.stop();
if (client.connect(serverObj, port)) { /where serverObj=192.168.1.41 that is my PC IP (server), and port=80/
client.println("POST /addNewNetworks.php HTTP/1.1");
client.print("Host: "); // SERVER ADDRESS HERE TOO
client.println(serverObj);
//client.print("Connection: close\n"); /i've tried both, using this line and without using it, and nothing changes/
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.println(data); /*where String data="idNetw=1&netwName=pepito\0";
} else { Serial.println("\nFailed when connecting to the server");}
If instead of printing it to the client, I print it to the Serial (terminal), I see:
POST /addNewNetworks.php HTTP/1.1
Host: 192.168.1.41
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
idNetw=1&netwName=pepito
thus, I understand this should be correct
The file in which I receive those data and process it is addNewNetworks.php:
<? //function that adds the information received to the table of networks in the database include("connect.php"); $link=Connection(); //this function works fine as I'm using it in the index.php file and it shows the content of the database //while the cue is not empty, receives pairs of Id_networks and name and stores it in the database if (!empty($_POST)) { $idNetw=$_POST["idNetw"]; $netwName=$_POST["netwName"]; $query = "INSERT INTO `wifi_networks` VALUES ('".$idNetw."','".$netwName."')"; } mysqli_query($query,$link); mysqli_close($link); ?>Can you help me to solve this problem?? I don't have more ideas to solve it and I have even tried to install wireshark and I can see the POST message, so it seems as the problem could be in the addNewNetworks.php file, but I cannot find it.