Guest User

Untitled

a guest
Feb 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. ****<?php
  2. function Connection(){
  3. $server="server";
  4. $user="user";
  5. $pass="pass";
  6. $db="database";
  7.  
  8. $connection = mysqli_connect($server, $user, $pass);
  9. //$db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'user', 'pass');
  10. if (!$connection) {
  11. die('MySQL ERROR: ' . mysql_error());
  12. }
  13.  
  14. mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );
  15. return $connection;
  16. }
  17. ?>****
  18.  
  19. **<?php
  20. include("connect.php");
  21.  
  22. $link=Connection();
  23. $temp1=$_POST["temp1"];
  24. $hum1=$_POST["hum1"];
  25. $query = "INSERT INTO `tempLog` (`temperature`, `humidity`)
  26. VALUES ('".$temp1."','".$hum1."')";
  27.  
  28. mysql_query($query,$link);
  29. mysql_close($link);
  30. header("Location: index.php");
  31. ?>**
  32.  
  33. **<?php
  34. include("connect.php");
  35.  
  36. $link=Connection();
  37. $result=mysql_query("SELECT * FROM `tempLog` ORDER BY `timeStamp` DESC",$link);
  38. ?>
  39. <html>
  40. <head>
  41. <title>Sensor Data</title>
  42. </head>
  43. <body>
  44. <h1>Temperature / moisture sensor readings</h1>
  45. <table border="1" cellspacing="1" cellpadding="1">
  46. <tr>
  47. <td>&nbsp;Timestamp&nbsp;</td>
  48. <td>&nbsp;Temperature 1&nbsp;</td>
  49. <td>&nbsp;Moisture 1&nbsp;</td>
  50. </tr>
  51. <?php
  52. if($result!==FALSE){
  53. while($row = mysql_fetch_array($result)) {
  54. printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td></tr>",
  55. $row["timeStamp"], $row["temperature"], $row["humidity"]);
  56. }
  57. mysql_free_result($result);
  58. mysql_close();
  59. }
  60. ?>
  61. </table>
  62. </body>
  63. </html>**
  64.  
  65. $connection = mysqli_connect($server, $user, $pass);
  66. if (!$connection) {
  67. die('MySQL ERROR: ' . mysql_error());
  68. }
  69.  
  70. mysql_select_db($connection,$db) or die( 'MySQL ERROR: '. mysql_error() );
  71. return $connection;
  72.  
  73. $connection = mysqli_connect($server, $user, $pass, $db);
  74. if (!$connection) {
  75. die('MySQL ERROR: ' . mysql_error());
  76. }
  77.  
  78. $connect = mysqli_connect($server, $user, $pass);
  79.  
  80. mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );
  81.  
  82. $link=Connection();
  83. $result=mysql_query("SELECT * FROM `tempLog` ORDER BY `timeStamp` DESC",$link);
  84.  
  85. $con = mysqli_connect('$host', '$user', '$pass', '$db');
  86.  
  87. $con = mysqli_connect("$host", "$user", "$pass", "$db");
Add Comment
Please, Sign In to add comment