element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Arduino and phpmyadmin
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 2 replies
  • Subscribers 401 subscribers
  • Views 589 views
  • Users 0 members are here
Related

Arduino and phpmyadmin

Former Member
Former Member over 13 years ago

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

 



  • Sign in to reply
  • Cancel
Parents
  • ntewinkel
    0 ntewinkel over 13 years ago

    I wonder about these 2 lines:

     

    "

    $temp1 = floatval ('temp1');

    $temp1 = $_GET['temp1'];

    "

     

    The second line overwrites the float value obtained by the first, doesn't it?

     

    Can you test the script by pointing a browser directly at it and then typing in what the Arduino would be sending?

     

    Also, in the Arduino code, should this be a println rather than a print?

    "

    client.print(temp1);

    "

     

    And is this line needed?

    "

    client.println(" HTTP/1.0");

    "

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • ntewinkel
    0 ntewinkel over 13 years ago

    I wonder about these 2 lines:

     

    "

    $temp1 = floatval ('temp1');

    $temp1 = $_GET['temp1'];

    "

     

    The second line overwrites the float value obtained by the first, doesn't it?

     

    Can you test the script by pointing a browser directly at it and then typing in what the Arduino would be sending?

     

    Also, in the Arduino code, should this be a println rather than a print?

    "

    client.print(temp1);

    "

     

    And is this line needed?

    "

    client.println(" HTTP/1.0");

    "

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube