<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aufgabe8</title>
<style>
#tr :hover { background-color: #66ccff }
</style>
<?php
if($_GET['action'] == "newEintrag")
{
newEintrag();
}
if($_GET['action'] == "updateEintrag")
{
updateEintrag();
}
if($_GET['action'] == "deleteEintrag")
{
deleteEintrag();
}
if($_GET['action'] == "EintragSpeichern")
{
EintragSpeichern();
}
if($_GET['action'] == "UpdateSave" )
{
UpdateSave();
}
else
{
};
?>
</head>
<body>
<?php
//DB verbindung
$sql ="Select * From aufgabe8 order by id";
$result = mysql_query($sql);
?>
<table id="gesamt_tabelle" width="90%" border="2" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC" >
<thead>
<td width="8%" align="center" bgcolor="#999999"> <span class="Stil2"> ID</span></td>
<td width="11%" align="center" bgcolor="#999999"> <span class="Stil2">Spalte1</span></td>
<td width="13%" align="center" bgcolor="#999999"> <span class="Stil2">Spalte2</span></td>
<td width="13%" align="center" bgcolor="#999999"> <span class="Stil2">Spalte3</span></td>
</thead>
<?php
while ($rows = mysql_fetch_object($result))
{
?>
<tbody>
<td width="8%" align="center" bgcolor="#999999"> <span class="Stil2" onclick="function(){<?php echo $rows->id ?>"> <?php echo $rows->id?></span></td>
<td width="8%" align="center" bgcolor="#999999"> <span class="Stil2"> <?php echo $rows->spalte1?></span></td>
<td width="8%" align="center" bgcolor="#999999"> <span class="Stil2"> <?php echo $rows->spalte2?></span></td>
<td width="8%" align="center" bgcolor="#999999"> <span class="Stil2"> <?php echo $rows->spalte3?></span></td>
</tbody>
<?php
}
?>
<form action="" method="get">
<input type="hidden" name="id" value="<?php echo $rows->id ?>"></input>
<input type="hidden" name="action" value="newEintrag"></input>
<button type="submit" >N</button>
</form>
<!--Bearbeiten Button -->
<form action="" method="get">
<input type="hidden" name="id" value="<?php echo $rows->id ?>"></input>
<input type="hidden" name="action" value="updateEintrag"></input>
<button type="submit" >B</button>
</form>
<!-- Lschen Button-->
<form action="" method="get">
<input type="hidden" name="id" value="<?php echo $rows->id ?>"></input>
<input type="hidden" name="action" value="deleteEintrag"></input>
<button type="submit" >L</button>
</form>
<?php
function newEintrag()
{
?>
<form action="" method="get">
Spalte1 <input type="text" name="spalte1"></input>
Spalte2 <input type="text" name="spalte2"></input>
Spalte3 <input type="text" name="spalte3"></input>
<input type="hidden" name="action" value="EintragSpeichern"></input>
<button type="submit">Speichern</button>
<?php
?>
</form>
<?php
}
?>
<?php function deleteEintrag()
{
//DB verbindung
$id = $_GET['id'];
$sql ="DELETE FROM aufgabe8 WHERE id = '$id'";
$result = mysql_query($sql);
}
?>
<?php function updateEintrag()
{
//DB verbindung
$id = $_GET['id'];
echo $id;
$sql ="Select * From aufgabe8 Where id = '$id'";
$result = mysql_query($sql);
while ($row = mysql_fetch_object($result))
{
?>
<form action="" method="get">
Spalte1 <input type="text" name="spalte1_update" value="<?php echo $row->spalte1 ?>">
Spalte2 <input type="text" name="spalte2_update" value="<?php echo $row->spalte2 ?>">
Spalte3 <input type="text" name="spalte3_update" value="<?php echo $row->spalte3 ?>">
<input type="hidden" name="id_update" value="<?php echo $row ->id; ?>">
<input type="hidden" name="action" value="UpdateSave">
<button type="submit" >Speichern</button>
</form>
<?php
}
}
?>
<?php function EintragSpeichern()
{
//DB verbindung
mysql_connect("$host", "$username","$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select $db_name");
$spalte1 = $_GET['spalte1'];
$spalte2 = $_GET['spalte2'];
$spalte3 = $_GET['spalte3'];
$sql="INSERT INTO aufgabe8 (spalte1, spalte2, spalte3)VALUES('$spalte1', '$spalte2', '$spalte3')";
$result = mysql_query($sql);
}
?>
<?php function UpdateSave()
{
//DB verbindung
$spalte1_update = $_GET['spalte1_update'];
$spalte2_update = $_GET['spalte2_update'];
$spalte3_update = $_GET['spalte3_update'];
$id_update = $_GET['id_update'];
$update="Update aufgabe8 SET spalte1='$spalte1_update',spalte2='$spalte2_update', spalte3='$spalte3_update' Where id ='$id_update'";
$result = mysql_query($update);
}
?>
</table>
</body>
</html>