Good evening gentlemen from the arduino forum. I have a question that I hope you can help me.
Let's imagine I have the following code on arduino:
#include <WiFi.h> // For the Wifi Shield of Arduino
// MySQL database connection:
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // It can be anything as long as it follows this structure
IPAddress server_addr(192,168,1,2); // IP of the MySQL server here (ipconfig in cmd and look IPV4)
char user[] = "dsm501a_project"; // MySQL user login username
char password[] = "12345"; // MySQL user login password
// Wifi connection
char ssid[] = "NETGEAR84";
char pass[] = "coolspider508";
WiFiClient client;
int A = 1;
void setup() {
Serial.begin(115200);
while (!Serial); // wait for serial port to connect. Needed for Leonardo only
// Begin WiFi section
int status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
else {
Serial.println("Connected to network");
IPAddress ip = WiFi.localIP();
Serial.print("My IP address is: ");
Serial.println(ip);
}
Serial.println("Connecting...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
}
else
Serial.println("Connection failed.");
}
void loop() {
if (client.connect(server_addr, 80)) {
client.print("GET /write_data.php?");
client.print("value=");
client.print(A);
client.println(" HTTP/1.1");
client.println("Host: 192.168.1.2");
client.println("Connection: close");
client.println();
client.println();
client.stop();
}
else {
Serial.println("--> connection failed\n");
}
delay(10000);
A++;
}
and I have the following php code:
<?php // Prepare variables for database connection $dbusername = "dsm501a_project"; // enter database username, I used "arduino" in step 2.2 $dbpassword = "12345"; // enter database password, I used "arduinotest" in step 2.2 $server = "localhost"; // IMPORTANT: if you are using XAMPP enter "localhost", but if you have an online website enter its address, ie."www.yourwebsite.com" // Connect to your database $dbconnect = mysql_pconnect($server, $dbusername, $dbpassword); $dbselect = mysql_select_db("test_arduino",$dbconnect); // Prepare the SQL statement $sql = "INSERT INTO test_arduino.test (Value) VALUES ('".$_GET["value"]."')"; // Execute SQL statement mysql_query($sql); ?>Why doesn't it work?
I am using MySQL workbench and WAMP64, and I am placing the php file in the folder wamp64 --> www and it does not work
What am I doing wrong?