Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function Connection(){
- $server="localhost";
- $user="root";
- $pass="123456";
- $db="database";
- $connection = mysqli_connect($server, $user, $pass);
- if (!$connection) {
- die('MySQL ERROR: ' . mysqli_error());
- }
- mysqli_select_db($connection,$db ) or die( 'MySQL ERROR: '. mysqli_error() );
- return $connection;
- }?>
- <?php
- include("connect.php");
- $link=Connection();
- $temp1=$_POST['temp1'];
- $hum1=$_POST['hum1'];
- $query = "INSERT INTO `templog` (`temperature`, `humidity`)
- VALUES ('".$temp1."','".$hum1."')";
- mysqli_query($link,$query);
- mysqli_close($link);
- header("Location: index.php");?>
- <?php
- include("connect.php");
- $link=Connection();
- $result=mysqli_query($link,"SELECT * FROM `templog` ORDER BY `timeStamp` DESC");
- ?>
- <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 </td>
- <td> Moisture </td>
- </tr>
- <?php
- if($result!==FALSE){
- while($row = mysqli_fetch_array($result)) {
- printf("<tr><td> %s </td><td> %s </td><td> %s </td></tr>",
- $row["timeStamp"], $row["temperature"], $row["humidity"]);
- }
- mysqli_free_result($result);
- mysqli_close($link);
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement