Script zum Abspeichern der Messwerte

<?php

$pdo = new PDO('mysql:host=localhost;dbname=cu-luft', 'cu-Luft', 'Knk');

// GET Werte einlesen
if(isset($_GET['Wert1'])) {$wert1 = $_GET['Wert1'];} else {$wert1 ="-------";}
if(isset($_GET['Wert2'])) {$wert2 = $_GET['Wert2'];} else {$wert2 ="-------";}
if(isset($_GET['Wert3'])) {$wert3 = $_GET['Wert3'];} else {$wert3 ="-------";}
if(isset($_GET['beschreibung'])) {$beschreibung = $_GET['beschreibung'];} else {$beschreibung ="-------";}
if(isset($_GET['info'])) {$info = $_GET['info'];} else {$info ="-------";}

// Eintrag in die Datenbank //   
$sql ="INSERT INTO `1` (`id`, `wert1`, `wert2`, `wert3`, `beschreibung`, `info`, `zeit`) 
     VALUES (NULL, '".$wert1."', '".$wert2."', '".$wert3."', '".$beschreibung."', '".$info."', CURRENT_TIMESTAMP);";
$pdo->query($sql);
?>

<!DOCTYPE html>
<html lang="de">
<head>
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Werte in Datenbank eingetragen.</h1>
<ul>
<li> Wert1: <?php echo $wert1; ?></li>
<li> Wert2: <?php echo $wert2; ?></li>
<li> Wert3: <?php echo $wert3; ?></li>
<li> Beschreibung: <?php echo $beschreibung; ?></li>
<li> info: <?php echo $info; ?></li>
<li> zeit: <?php echo $zeit; ?></li>
</ul>
</body>
</html>

Script zum Anzeigen der Messwerte

<?php
$pdo = new PDO('mysql:host=localhost;dbname=cu-luft', 'cu-Luft', 'Knk');
/* Verbindungsdaten */
// GET Werte einlesen
if(isset($_GET['messung'])) {$beschreibung = $_GET['messung'];} else {$beschreibung ="";}
?>
<!DOCTYPE html>
<html lang="de">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="refresh" content="30">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Raumklima</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="css/font-awesome.min.css" />
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'></script>  
  </head> 
  <body>

    
<!--  START -->
<div class="container">        
<h2>Messwerte:</h2>
		
<!-- Beginn des Formulars -->
<div class="col-xs-12 col-sm-6 col-md-6">
<form name="Messung"   method="GET">	
<div class="form-group">
<select class="form-control" id="messung" name ="messung">	
	<?php
		$sql ="SELECT DISTINCT `beschreibung` FROM `1` ";
			foreach ($pdo->query($sql) as $row) {
				echo"<option value=\"".$row['beschreibung']."\">".$row['beschreibung']."</option>";
			}
		?>
</select>
</div>
<button type="reset" class="btn col-4  btn-primary">Zur&uuml;cksetzen</button>
<button type="submit" class="btn col-4 btn-primary">Absenden</button>
</form>
</div>
	
<?php
if($beschreibung ==""){
$sql= "SELECT * FROM `1` ORDER BY `id` DESC LIMIT 500";
}
else {
$sql= "SELECT * FROM `1` where `beschreibung`='".$beschreibung."' ORDER BY `id` DESC LIMIT 500";
}

echo "<table class=\"table table-striped table-bordered\">";
echo "<tr> <th>id</th><th>Wert 1  </th><th> Wert 2 </th><th> Wert 3  </th><th> Beschreibung </th><th> Info</th><th> Zeit</th></tr>";

foreach ($pdo->query($sql) as $row) {	
 echo "<tr><td>".$row['id']."</td><td>".$row['wert1']."</td><td>".$row['wert2']."</td><td>".$row['wert3']."</td><td>".$row['beschreibung']."</td><td>".$row['info']."</td><td>".$row['zeit']."</td></tr>";
}
echo "</table>";
?>			 
	  
</div></body></html>

  • arduino/php.txt
  • Zuletzt geändert: 2022/06/02 18:00
  • von khirling