code: Termine

Codes

Termine:

Php code zum eine Verbindung mit der Datenbank herzustellen.
Die Uhrzeit muss natürlich auch festgelegt werden.
<?php

session_start();

$db = mysqli_connect("localhost", "max", "muster", "db_beispiel");

$pdo = new PDO('mysql:host=localhost;dbname=db_beispiel', 'max', 'muster');

date_default_timezone_set("Europe/Berlin");
$timestamp = time();
$aktdatum = date("Y-m-d",$timestamp);

?>
Formular um Termine hinzuzufügen:
<h2 align="center">Termine</h2>

<h3>Termin hinzufügen</h3>
<form action="" method="post">
Benutzer:<br>
<input type="text" name="user"><br>
Datum:<br>
<input type="date" name="date"><br>
Zeit:<br>
<input type="time" name="time"><br>
Ort:<br>
<input type="text" name="ort"><br><br>
Anlass:<br>
<input type="text" size="50" name="anlass"><br>
Beschreibung:<br>
<textarea cols="100" rows="9" name="bung"></textarea><br><br>

<input type="submit" value="Eintragen">
</form>
Daten in die Tabelle einfügen und ausgeben.
<?php

$user = htmlentities($_POST['user']);
$date = $_POST['date'];
$time = $_POST['time'];
$ort = htmlentities($_POST['ort']);
$anlass = htmlentities($_POST['anlass']);
$bung = htmlentities($_POST['bung']);

$statement = $pdo->prepare("INSERT INTO termine ( datum, anlass, beschreibung, user, ort, time) VALUES (:date, :anlass, :beschreibung, :user, :ort, :time)");
$result = $statement->execute(array( 'date' => $date, 'anlass' => $anlass, 'beschreibung' => $bung, 'user' => $user, 'ort' => $ort, 'time' => $time));

if($result){
echo '<br>Erfolgreich hinzugefügt<br><br>';
}

?>
<hr>
<h3>Bevorstehende Termine</h3>
<?php

$detail = mysqli_query($db, "SELECT * FROM termine");

while($row = mysqli_fetch_object($detail))
{
$id = $row->id;
$user = $row->user;
$datum = $row->datum;
$anlass = $row->anlass;
$bung = nl2br($row->beschreibung);
$ort = $row->ort;
$time = $row->time;
$created = $row->erstellt;
}


if(isset($anlass)){

$max = $id+1;

for($idra=1; $idra < $max; $idra++){
if($idra <= $max)
{

$detaila = mysqli_query($db, "SELECT * FROM termine WHERE id = '$idra'");

while($row = mysqli_fetch_object($detaila))
{
$id = $row->id;
$user = $row->user;
$datum = $row->datum;
$anlass = $row->anlass;
$bung = nl2br($row->beschreibung);
$ort = $row->ort;
$time = $row->time;
$created = $row->erstellt;
}

if($aktdatum <= $datum){

if($idra == $id){
?>

<h4><?php echo $time;?> <?php echo $datum;?></h4>

<table width="100%">
<tr>
<td bgcolor="orange" width="5%">
Anlass:
</td>
<td width="25%">
<?php echo $anlass;?>
</td>
<td bgcolor="orange" width="5%">
Erstellt
</td>
<td width="25%">
<?php echo $created;?>
</td>
</tr>
<tr>
<td bgcolor="orange">
Ort
</td>
<td>
<?php echo $ort;?>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td>
<?php echo $bung;?>
</td>
</tr>
</table>
<br><br>

<?php
}
}
}
}
}
?>
Dazu wird natürlich noch eine Tabelle in der Datenbank benötigt
Tabelle-->termine
id , int(11)
verein , varchar(300)
datum , date
anlass , varchar(3000)
beschreibung , varchar(5000)
user , varchar(200)
ort , varchar(200)
time , time
erstellt , timestamp CURRENT_TIMESTAMP
Marc Disch Blog Vefko