Go Down

Topic: Connecting Arduino with phpMyadmin (Read 2543 times) previous topic - next topic

Vincent1992

Hi,

I working on a project to build a weather station with an Arduino that measures temperature, pressure values etc. These values  will then be stored in a MySQL database which I'll use to plot a live data on a web server.  I'm using Apache web server with phpMyadmin installed. My problem is I don't know how to write a PHP code to send data from my Arduino to the database. I'll appreciate it if you can help me.

keeper63

Before others post here - this has been done numerous times; why are you unable to find these resources (to everyone else, if you post a link to such a resource, you are doing the OP a disservice - how is s/he supposed to ever learn how to do research themselves)?
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Vincent1992

Hi,

I found this code which I placed in the htdocs folder of apache but my database is still not showing the arduino value. How can I run this code please as I'm new to web servers?




<html><body>
test server page<br>
<?
  $temp1 = $HTTP_GET_VARS['temp1'];
  if(strlen($temp1) < 1) $temp1 = "0";

  $dbcnx = mysql_connect("localhost","user", "password");

  if(!$dbcnx)
  {
    echo( "<P>Unable to connect to the database server at this time.</P></body></html>" );
    exit();
  }

  if(!mysql_select_db("test") )
  {
    echo( "<P>Unable to locate the test database at this time.</P></body></html>" );
    exit();
  }

  $result = mysql_query("INSERT INTO temperatures (temp1) VALUES ($temp1)");
  if(!$result) echo("<P>Insert failed</P>");
  else echo("<P>Insert ok</P>");

  mysql_close($dbcnx);
  echo('temp1 = ' . $temp1 . ' ');
?>
</body>
</html>

Chagrin

Did you create the "temperatures" table in the database?

Code: [Select]
CREATE TABLE `temperatures` (
  `event_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `temp1` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`event_id`)
) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=latin1;


Vincent1992

Hi

I created the database but it's called 'temperatures' while the table is called 'temp'. Since I already have Apache do I still need Ethernet shield before I can upload my data to the web server?


Go Up