mirror of
https://gitlab.com/harald.mueller/aktuelle.kurse.git
synced 2024-11-24 02:31:58 +01:00
165 lines
4.4 KiB
PHP
165 lines
4.4 KiB
PHP
|
<?php
|
|||
|
// Systemeinstellungen
|
|||
|
$id = "root";
|
|||
|
$pw = "";
|
|||
|
$host = "localhost";
|
|||
|
$database = "test";
|
|||
|
$table = "artikel1";
|
|||
|
|
|||
|
// Einstellungen Ende
|
|||
|
|
|||
|
$conn_id = mysql_connect ($host, $id, $pw);
|
|||
|
mysql_select_db($database,$conn_id);
|
|||
|
|
|||
|
// L<>scht einen Artikel aus der Datenbank
|
|||
|
if ($action == "loeschen") {
|
|||
|
Mysql_query ("delete from $table where nr = <20>'$nr'");
|
|||
|
$meldung = "Der Artikel wurde gel<65>scht.";
|
|||
|
|
|||
|
// Aktualisiert einen Datensatz
|
|||
|
} elseif($action == "save") {
|
|||
|
mysql_query("update $table set artnr = $artnr, titel = '$titel', preis = '$preis', inhalt =
|
|||
|
'$inhalt' where nr = '$nr'");
|
|||
|
$meldung = "Der Artikel wurde upgedated.";
|
|||
|
|
|||
|
// F<>gt einen neuen Artikel hinzu
|
|||
|
} elseif ($action == "neu") {
|
|||
|
mysql_query ("insert into $table (titel, artnr, preis, inhalt) VALUES
|
|||
|
('$titel', '$artnr', '$preis', '$inhalt')");
|
|||
|
$meldung = "Der Artikel wurde hinzugef<65>gt.";
|
|||
|
|
|||
|
|
|||
|
// Selektiert den ausgew<65>hlten Artikel zu Updaten
|
|||
|
} elseif ($action == "update") {
|
|||
|
|
|||
|
$result = mysql_query("select * from $table where nr = '".$nr. "'");
|
|||
|
$titel = mysql_result($result,0, "titel");
|
|||
|
$artnr = mysql_result($result,0, "artnr");
|
|||
|
$preis = mysql_result ($result,0, "preis");
|
|||
|
$inhalt = mysql_result ($result,0, "inhalt");
|
|||
|
?>
|
|||
|
|
|||
|
<table>
|
|||
|
<form action=<?php echo $PHP_SELF; ?> method=post>
|
|||
|
<input type=hidden name=action value="save">
|
|||
|
<input type=hidden name=nr VALUE="<? echo $nr ?>">
|
|||
|
<tr>
|
|||
|
<td>Art.-Nr.</td>
|
|||
|
<td><input type=text name="artnr" value="<? echo $artnr ?>"></td>
|
|||
|
</tr><tr>
|
|||
|
<td>Titel</td>
|
|||
|
<td><input type=text name="titel" value="<? echo $titel ?>"></td>
|
|||
|
</tr><tr>
|
|||
|
<td>Preis</td>
|
|||
|
<td><input type=text name="preis" value="<? echo $preis ?>"></td>
|
|||
|
</tr><tr>
|
|||
|
<td>Text</td>
|
|||
|
<td><textarea name="inhalt"><? echo $inhalt ?></textarea><td>
|
|||
|
</tr><tr>
|
|||
|
</tr> </td>
|
|||
|
<td><input type=submit value="Artikel Updaten"></form></td>
|
|||
|
</tr>
|
|||
|
</table><p>
|
|||
|
|
|||
|
<?php
|
|||
|
|
|||
|
// Formular f<>r ein neues Produkt
|
|||
|
} elseif($action == "formneu" ) {
|
|||
|
|
|||
|
?>
|
|||
|
<table>
|
|||
|
<form action=<?php echo $PHP_SELF; ?> method=post>
|
|||
|
<input type=hidden name=action value="neu">
|
|||
|
<tr>
|
|||
|
<td>Art.-Nr.</td>
|
|||
|
<td><input type=text name="artnr"></td>
|
|||
|
</tr><tr>
|
|||
|
<td>Titel</td>
|
|||
|
<td><input type=text name="titel"></td>
|
|||
|
</tr><tr>
|
|||
|
<td>Preis</td>
|
|||
|
<td><input type=text name="preis"></td>
|
|||
|
|
|||
|
|
|||
|
</tr><tr>
|
|||
|
<td>Text</td>
|
|||
|
<td><textarea name="inhalt"></textarea></td>
|
|||
|
</tr><tr>
|
|||
|
<td> </td>
|
|||
|
<td><input type=submit value="Neuen Artikel hinzuf<75>gen"></form></td>
|
|||
|
</tr>
|
|||
|
</table><p>
|
|||
|
|
|||
|
<?php
|
|||
|
// Gibt alle Datens<6E>tze aus der Datenbank aus.
|
|||
|
} else {
|
|||
|
|
|||
|
|
|||
|
|
|||
|
echo "<ol><b>Alle Artikel in der <20>bersicht:</b>";
|
|||
|
echo "<br>";
|
|||
|
echo "<table border= 'l' width='700'>";
|
|||
|
echo "<tr bgcolor='#00cc00'><td width='100'><b>Art.-Nr.<b></td>
|
|||
|
<td width='100'><b>Artikel</b></td>
|
|||
|
<td width='100'><b>Preis</b></td>
|
|||
|
<td width='300'><b>inhalt</b></td>
|
|||
|
<td width='50' ><b>Update</b></td>
|
|||
|
<td width='50'><b>L<EFBFBD>schen</b></td></tr>";
|
|||
|
|
|||
|
$result = mysql_query("select * from $table");
|
|||
|
if ($num = mysql_num_rows($result)) {
|
|||
|
// Ausgabe der Datens<6E>tze, wenn vorhanden
|
|||
|
for ($i=0;$i < $num; $i++) {
|
|||
|
|
|||
|
/* zus<EFBFBD>tzlicher Counter
|
|||
|
$z++; //bincounter
|
|||
|
if($z == 1)
|
|||
|
{ $bgColor = "#CCCCCC"; }
|
|||
|
else
|
|||
|
{ $bgColor = "#FFFFFF"; } */
|
|||
|
// Gibt alle Datens<6E>tze in wechselfarbigen Tabellenreihen aus(1).
|
|||
|
|
|||
|
/* Abfrage der Variable ($i/2) ergibt eine Floatzahl
|
|||
|
if(strpos(($i/2),".")==false)
|
|||
|
{ $bgColor = "#CCCCCC"; }
|
|||
|
else
|
|||
|
{ $bgColor = "#FFFFFF"; } */
|
|||
|
// Gibt alle Datens<6E>tze in wechselfarbigen Tabellenreihen aus(2).
|
|||
|
|
|||
|
$bgColor = $bgColor=="#ffffff" ? "#888888" : "#ffffff";
|
|||
|
// Streifen-Muster / verkuerzte if(bedingung){ } else{}-Verzweigung
|
|||
|
// Bedingung ? Erfuellt-Fall : Nichterfuellt-Fall
|
|||
|
// Falls der Inhalt der Variable $bgColor #ff00ff" ist, wird er auf
|
|||
|
// #888888 gesetzt, ansonsten auf #ff00ff
|
|||
|
|
|||
|
$nr = mysql_result($result,$i,"nr");
|
|||
|
$artnr = mysql_result($result,$i,"artnr");
|
|||
|
$preis = mysql_result($result,$i,"preis");
|
|||
|
$titel = mysql_result($result,$i,"titel");
|
|||
|
$inhalt = mysql_result($result,$i,"inhalt");
|
|||
|
|
|||
|
echo "<tr bgColor = \"$bgColor\">";
|
|||
|
echo "<td>$artnr</td>";
|
|||
|
echo "<td>$titel</td>";
|
|||
|
echo "<td>$preis Fr. -</td>";
|
|||
|
echo "<td>$inhalt</td>";
|
|||
|
echo "<td><a href=\"$PHP_SELF?nr=$nr&action=update\">Update</a></td>";
|
|||
|
echo "<td><a href=\"$PHP_SELF?nr=$nr&action=loeschen\">L<>schen</a></td>"; }
|
|||
|
echo "</tr>";
|
|||
|
|
|||
|
/*if($z==1)
|
|||
|
{ $z = -1;} //bincounter 1 | 0
|
|||
|
|
|||
|
} */
|
|||
|
} else echo "<tr><td colspan='6' width='100%'>kein Artikel vorhanden!</td></tr>";
|
|||
|
echo "</table>";
|
|||
|
echo "</ol>";
|
|||
|
}
|
|||
|
echo "<ol>";
|
|||
|
if (!$meldung) $meldung = "Optionen<P>";
|
|||
|
echo "$meldung";
|
|||
|
|
|||
|
echo "<p><a href=$PHP_SELF>Zur Startseite</a>";
|
|||
|
echo " - <a href=$PHP_SELF?action=formneu>Neuen Artikel einf<6E>gen</a>";
|
|||
|
echo "</ol>";
|
|||
|
?>
|