Hi guys. I am new to arduino and i want to make a project for my university, using Temperature Sensors and uploading the results to phpMyadmin. I am checking everywhere to find a solution but i have totally "crushed"!!!
The problem is that while it seems to be a connection between arduino sketch and phpMyadmin in my database fields, the sketch returns only 0.00 and i can't find the problem. I thank you all in advance. Every possible answer is thankfully accepted.
This is the part of Arduino sketch that transfers data to my database
void loop(void)
{
if(!connected) {
//Serial.println("Not connected");
if (client.connect(serverip,80)){
sensors.requestTemperatures(); // send the request for temperature to sensors
float temp1 = sensors.getTempCByIndex(0);
// take temp reading from sensor "i" and store it to temp1
Serial.print("Temp is ");
Serial.println(temp1);
Serial.println("Sending to Server: ");
client.print("GET /mysql_connect.php?temp1=");
Serial.print("GET /mysql_connect.php?temp1=");
client.print(temp1);
Serial.print(temp1);
client.println(" HTTP/1.0");
Serial.println(" HTTP/1.0");
client.println();
Serial.println();
delay(20000); // send the temperature every 20 sec
}
This is my mysql_connect.php file
<?php
if (isset($_GET['temp1']))
{
$temp1 = floatval ('temp1');
$temp1 = $_GET['temp1'];
$con = mysql_connect("host","username","password");
if (!$con)
{
die('could not connect: ' .mysql_error());
}
mysql_select_db("temp_database", $con);
$sql="INSERT INTO temperatures (temp1) VALUES ($temp1)";
echo "inserted correctly \n";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
if (mysql_query($sql,$con)){
echo "1 record added";
}
mysql_close($con);
}
?>
In this part of my php code:
$sql="INSERT INTO temperatures (temp1) VALUES ($temp1)";
when i just put a random float (e.g. 42.05) it works perfectly, but when i leave it just like above and "expect the communication" between Arduino and php i have the problem. I type in my browser:
localhost/mysql_connect.php?temp1=
And the message i get is:
Error: Column count doesn't match value count at row 1