Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add.php
- ------------------------------------------------------------------------------------------------------------------------------------------
- <?php
- $server="localhost";
- $user="root";
- $pass="";
- $db="arduino";
- ?>
- <html>
- <head>
- <title>Test for uploading data</title>
- </head>
- <body>
- <?php
- if(isset($_POST['temp1']))
- {
- $temp1=$_POST['temp1'];
- $hum1=$_POST['hum1'];
- $link=mysqli_connect($server, $user, $pass );
- if(!$link)
- {echo mysql_error();
- echo "<br><br>";
- }
- if(!mysqli_select_db($link,"arduino"))
- {echo mysql_error();
- echo "<br><br>";
- }
- $query = "INSERT INTO templog(temperature,humidity) VALUES ($temp1,$hum1)";
- if(!mysqli_query($link,$query))
- {echo mysql_error();
- echo "<br><br>";
- }
- // mysql_close($link);
- }
- ?>
- <form action="add.php" method="POST">
- value for temp1<br>
- <input type="text" name="temp1"><br><br>
- <input type="text" name="hum1"><br><br>
- <input type="submit"><br>
- </form>
- </body>
- </html>
- ------------------------------------------------------------------------------------------------------------------------------------------
- index.php
- <?php
- include("connect.php");
- $link=Connection();
- $result=mysql_query('SELECT * FROM tempLog ORDER BY timeStamp'); //DESC",$link);
- ?>
- <html>
- <head>
- <title>Sensor Data</title>
- </head>
- <body>
- <h1>Temperature / moisture sensor readings</h1>
- <table border="1" cellspacing="1" cellpadding="1">
- <tr>
- <td> Timestamp </td>
- <td> Temperature 1 </td>
- <td> Moisture 1 </td>
- </tr>
- <?php
- if($result!==FALSE){
- while($row = mysql_fetch_array($result)) {
- printf("<tr><td> %s </td><td> %s </td><td> %s </td></tr>",
- $row["timeStamp"], $row["temperature"], $row["humidity"]);
- }
- mysql_free_result($result);
- // mysql_close();
- }
- ?>
- </table>
- </body>
- </html>
- ----------------------------------------------------------------------------------------------------------------------------------------
- connect.php
- <?php
- function Connection(){
- $server="localhost";
- $user="root";
- $pass="";
- $db="arduino";
- $connection = mysql_connect($server, $user, $pass);
- if (!$connection) {
- die('MySQL ERROR: ' . mysql_error());
- }
- mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );
- return $connection;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement