Content Management System für das Artikel-Verwaltungssystem
Die Grundanforderung von webbasierten Systemen ist oft identisch: Es müssen (teil-)dynamische HTML-Seiten dargestellt sowie Verbindungen zu einer Datenbank hergestellt werden. Diese grundlegenden Funktionalitäten werden daher in einem Basissystem zusammengefasst, auf das Sie als Programmierer zugreifen können, um schnell und flexibel Inhalt und Logik zu erstellen. Unser Basissystem hat eine festgelegte Ordnerstruktur, die die Übersichtlichkeit eines Projektes während der Implementierung garantieren soll. Dabei werden auf oberster Ebene alle Dateien erstellt, da nicht so viel Dateien für das Artikel-Verwaltungssystem gebraucht werden.labconnect.php
Diese Datei baut die Verbindung mit dem MYSQL-Server auf. Dabei müssen der Hostname, Datenbankname, Benutzername und das Passwort bekannt und richtig angegeben werden. Der Inhalt könnte wie folgt aussehen:<?php mysql_connect("localhost", "your_username", "your_password"); mysql_select_db("your_databasename"); ?>
labheader.php
Diese Datei beinhaltet alle CSS-Dateien, die für das ganze Projekt verwendet werden. Diese wird in jede Hauptdatei eingebunden.<?php echo "<html xmlns='http://www.w3.org/1999/xhtml'>"; echo "<head>"; echo "<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />"; echo "<title>Article by Mehdi Bandegani</title>"; echo " <link href='http://www.bandegani.de/itkurs/css/bootstrap.min.css' rel='stylesheet'> <link href='http://www.bandegani.de/itkurs/css/metisMenu.min.css' rel='stylesheet'> <link href='http://www.bandegani.de/itkurs/css/timeline.css' rel='stylesheet'> <link href='http://www.bandegani.de/itkurs/css/startmin.css' rel='stylesheet'> <link href='http://www.bandegani.de/itkurs/css/morris.css' rel='stylesheet'> <link href='http://www.bandegani.de/itkurs/css/dataTables.bootstrap.css' rel='stylesheet'> <link href='http://www.bandegani.de/itkurs/css/dataTables.responsive.css' rel='stylesheet'> <link href='http://www.bandegani.de/itkurs/css/bootstrap-social.css' rel='stylesheet'> <link href='http://www.bandegani.de/itkurs/css/font-awesome.min.css' rel='stylesheet' type='text/css'> "; echo "<link rel='stylesheet' href='http://www.bandegani.de/itkurs/css/site.css'>"; echo "<link href='http://www.bandegani.de/itkurs/highlight/styles/github.css' rel='stylesheet'>"; echo "<body>"; // Gesamter Bereich:Anfang von wrapper echo "<div id='wrapper'>"; // Navigationsanfang echo "<nav class='navbar navbar-default navbar-fixed-top' role='navigation' style='background-color: #F0F8FF;'> <ul class='nav navbar-nav'> <li><a href='index.php'><span class='fa fa-home'></span> HOME</a></li> <li><a href='labarticledescription.php'><span class='fa fa-Artikel'></span> DESCRIPTION</a></li>"; if ($_SESSION['id']>0){ echo "<li><a href='lablogout.php'><span class='mif-user-minus icon'>LOGOUT</span></a></li>"; } else { echo "<li><a href='lablogin.php'><span class='mif-user-plus icon'>LOGIN</span></a></li>"; } echo "</ul> </nav> "; ?>
labfooter.php
Diese Datei enthält alle js-Dateien, die für das Projekt benötigt werden. Diese wird in jede Hauptdatei eingebunden.<!-- ende id='wrapper' in labheader.php--> </div> <!-- end id="page-wrapper" in labsidenav.php --> </div> </div> </div> </div> <!-- /#wrapper --> <footer class='page-footer font-small blue-grey lighten-5'> <div class='footer-copyright text-center py-3' style='background-color: #F0F8FF;'> <ul class='list-unstyled'> <br /> <li> <a href='https://www.haw-hamburg.de/startseite.html'>HAW-Hamburg</a> </li> <li> <a href='https://design.haw-hamburg.de/home/das-department-design/'>Departement Design</a> </li> <li> <a href='https://vorlesungsverzeichnis.design.haw-hamburg.de/'>Vorlesungsverzeichnis</a> </li> </ul> <a href='http://www.bandegani.de/'> <span class='fa fa-copyright'></span>2020 Copyright bandegani.de </a> </div> </footer> <script src="http://www.bandegani.de/itkurs/js/jquery.min.js"></script> <script src="http://www.bandegani.de/itkurs/js/bootstrap.min.js"></script> <script src="http://www.bandegani.de/itkurs/js/metisMenu.min.js"></script> <script src="http://www.bandegani.de/itkurs/js/startmin.js"></script> <script src="http://www.bandegani.de/itkurs/js/dataTables/jquery.dataTables.min.js"></script> <script src="http://www.bandegani.de/itkurs/js/dataTables/dataTables.bootstrap.min.js"></script> <script src='http://www.bandegani.de/itkurs/js/jquery.min.js'></script> <script src='http://www.bandegani.de/itkurs/js/bootstrap.min.js'></script> <script src='http://www.bandegani.de/itkurs/js/metisMenu.min.js'></script> <script src='http://www.bandegani.de/itkurs/js/startmin.js'></script> <script src='http://www.bandegani.de/itkurs/js/dataTables/jquery.dataTables.min.js'></script> <script src='http://www.bandegani.de/itkurs/js/dataTables/dataTables.bootstrap.min.js'></script> <script> // tooltip demo $('.tooltip-demo').tooltip({ selector: '[data-toggle=tooltip]', container: 'body' }) // popover demo $('[data-toggle=popover]').popover() $('.carousel').carousel() </script> </body> </html>
<div class="navbar-default sidebar" role="navigation" style='background-color: #F0F8FF;'> <div class="sidebar-nav navbar-collapse" style='background-color: #F0F8FF;'> <ul class="nav" id="side-menu"> <li class="sidebar-search"> <div class="input-group custom-search-form"> <input type="text" class="form-control" placeholder="Search..."> <span class="input-group-btn"> <button class="btn btn-primary" type="button"> <i class="fa fa-search"></i> </button> </span> </div> <!-- /input-group --> </li> <?php session_start(); if($_SESSION['id']>=1) { echo "<li>"; echo "<a href='http://www.bandegani.de/itkurs/labarticle/#'>Manage record<span class='fa arrow'></span></a>"; echo "<ul class='nav nav-second-level'>"; echo "<li><a href='http://www.bandegani.de/itkurs/labarticle/labshowarticle.php'>Show</a></li>"; echo "<li><a href='http://www.bandegani.de/itkurs/labarticle/labeditarticle.php'>Edit</a></li>"; echo "<li><a href='http://www.bandegani.de/itkurs/labarticle/labdeletearticle.php'>Delete</a></li>"; echo "<li><a href='http://www.bandegani.de/itkurs/labarticle/labinsertarticle.php'>Insert</a></li>"; echo "<li><a href='http://www.bandegani.de/itkurs/labarticle/labsearcharticle.php'>Search</a></li>"; echo "<li><a href='http://www.bandegani.de/itkurs/labarticle/labsortarticle.php'>Sort</a></li>"; echo "</ul>"; echo "<li><a href='http://www.bandegani.de/itkurs/labarticle/lablogout.php'>Logout</a></li>"; echo "</li>"; } ?> </ul> </div> </div> <div id="page-wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12">
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include('labconnect.php'); ?> <div class='container-fluid'> <div class='row'> <div class='col-lg-12'> <div class='panel panel-default'> <div class='panel-heading'> <b>Dateistruktur des Artikel-Verwaltungssystems</b> </div> <div class='panel-body'> <div class='table-responsive'> <table class="table"> <thead> <tr> <th>Dateiname</th> <th>Beschreibung</th> <th>Abhängigkeiten</th> </tr> </thead> <tbody> <tr> <td>index.php</td> <td>Liste der Dateien</td> <td>labheader.php,labsidenav.php' und labfooter.php</td> </tr> <tr class='info'> <td>labheader.php</td> <td>Menüpunkte</td> <td>Hauptdatei und CSS-Dateien</td> </tr> <tr> <td>labfooter.php</td> <td>Footer Bereich</td> <td>Hauptdatei und JS-Dateien</td> </tr> <tr class='info'> <td>labsidenav.php</td> <td>Linker Navigation-Bereich</td> <td>Hauptdatei</td> </tr> <tr> <td>labarticledesciption.php</td> <td>Dokumentation für das Artikel-Verwaltungssystem</td> <td>Hauptdatei</td> </tr> <tr class='info'> <td>lablogin.php</td> <td>Benutzeranmeldung</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr> <td>labshowarticle.php</td> <td>Benutzerabhängige Artikel anzeigen</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr class='info'> <td>labinsertarticle.php</td> <td>Benutzerabhängige Artikel hinzufügen</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr> <td>labeditarticle.php</td> <td>Benutzerabhängige Artikel ändern</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr class='info'> <td>labdeletearticle.php</td> <td>Benutzerabhängige Artikel löschen</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr> <td>labsearcharticle.php</td> <td>Benutzerabhängige Artikel suchen</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr class='info'> <td>labsortarticle.php</td> <td>Benutzerabhängige Artikel sortieren</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> </tbody> </table> </div></div></div> </div></div></div> <?php include ("labfooter.php"); ?>
Tabellenschema für das Artikelsystem
Datenbanktabelle lab_tblusers
CREATE TABLE IF NOT EXISTS `lab_tblusers` ( `id` int(11) NOT NULL, `name` varchar(50) DEFAULT NULL, `prename` varchar(50) DEFAULT NULL, `modified` datetime DEFAULT NULL, `email` varchar(100) DEFAULT NULL, `password` varchar(32) DEFAULT NULL ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ALTER TABLE `lab_tblusers` ADD PRIMARY KEY (`id`); ALTER TABLE `lab_tblusers` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
Datenbanktabelle (lab_tblarticle)
CREATE TABLE IF NOT EXISTS `lab_tblarticle` ( `id` int(11) NOT NULL, `articledate` date NOT NULL, `idusers` int(11) NOT NULL, `title` varchar(50) NOT NULL, `article` text NOT NULL ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ALTER TABLE `lab_tblarticle` ADD PRIMARY KEY (`id`); ALTER TABLE `lab_tblarticle` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
Der Inhalt der Datei (lablogin.php)
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include ('labconnect.php'); echo "<div class='row'> <div class='col-md-4 col-sm-4 col-xs-12'></div> <div class='col-md-4'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Login - Formular</h2> </div> <div class='panel-body'>"; echo "<form enctype='multipart/form-data' method='post' action='lablogin.php'>"; echo "<div class='form-group'> <label class='control-label' for='inputUsername'>Username:</label> <input type='text' name='email' class='form-control' id='inputUsername' required> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputPassword'>Password:</label> <input type='Password' name='password' class='form-control' id='inputPassword' required> <div style='height: 15px;'></div> </div> <div class='form-group'> <button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-lock'></span> Login</button> </div>"; echo "</form>"; echo "</div></div></div></div>"; if(isset($_POST['send'])) { session_start(); $email=$_POST['email']; $password= $_POST['password']; $email=stripcslashes($email); $password= md5($password); $sqlstr = "select * from lab_tblusers where email='$email' AND password='$password'"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_fetch_array($res); if ($num['email']==$email && $num['password']==$password){ $_SESSION['id'] = $num['id']; $_SESSION['email'] = $email; header("Location: index.php"); } else { echo "<div class='row'> <div class='col-md-8 col-sm-4 col-xs-12'></div> <div class='col-md-8'> <span class='label label-danger'>You could not be registered. You must be logged in to see this page.!</span> </div></div>"; } mysql_free_result($res); } include("labfooter.php"); ?>
Soll sich die angemeldete Person am System abmelden, ist die Datei (lablogout.php) vorgesehen.
Der Inhalt der Datei (lablogout.php)
<?php include("labconnect.php"); include("labheader.php"); include('labsidenav.php'); session_start(); session_destroy(); echo " <div class='row'> <div class='col-md-4 col-sm-4 col-xs-12'></div> <div class='col-md-4'> <span class='label label-success'>You are Logout!</span> </div></div>"; echo "<hr>"; include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (lab_tblcategories) hinzugefügt werden. Die Abb.4.5.1, Abb.4.5.2 und Abb.4.5.3 zeigen den Ablauf, um einen Datensatz in die Tabelle (lab_tblcategories) hinzuzufügen.
Abb. 4.5.1 Kategorie-Formular für einen neuen Datensatz (labinsertcategories.php)
Abb. 4.5.2 Kategorie-Formular bei einem neuen Datensatz (labinsertcategories.php)
Abb. 4.5.3 Hinzugefügter Datensatz (labinsertcategories.php)
Der Inhalt der Datei (labinsertcategories.php)
<?php session_start(); if(isset($_POST['send'])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $sqlstr = "insert lab_tblcategories" . "(name, link, activ, description) values " . "('" . $_POST["name"] . "', " . "'" . $_POST["link"] . "', " . "'" . $activ . "', " . "'" . $_POST["description"] . "')"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num>0) { display_list_categories(); } else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "No record has been added to the database!"; echo "</div>"; echo "</div></div>"; } mysql_free_result($res); }else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-6'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Insert category - Form</h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=InsertCategories'>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputName'>Name:</label>"; echo "<input type='text' name='name' class='form-control' id='inputName' placeholder='Enter Category name'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputLink'>Link:</label>"; echo "<input type='text' name='link' class='form-control' id='inputLink' placeholder='Enter link'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ'><br />"; echo "<small class='text-muted'>If the entry should be active, the checkbox must be clicked!</small>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputDescription'>Description:</label>"; echo "<textarea data-role='textarea' name='description' class='form-control' id='inputDescription'></textarea>"; echo "</div>"; echo "<div class='form-group'>"; echo "<button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-send'></span> Insert the record</button>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; } function display_list_categories(){ $sqlstr = "select * from lab_tblcategories ORDER BY id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>List the database: <small>lab_tblcategories</small></h2> </div> <div class='panel-body'>"; echo "<table class='table'>"; echo "<thead>"; echo "<tr><th>Id</th>"; echo "<th>Name</th>"; echo "<th>Link</th>"; echo "<th>Activ</th>"; echo "<th>Description</th>"; echo "</tr>"; echo "</thead><tbody>"; while ($row = mysql_fetch_assoc($res)) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td>" . $row["name"] . "</td>"; echo "<td>" . $row["link"] . "</td>"; echo "<td>" . $row["activ"] . "</td>"; echo "<td>" . $row["description"] . "</td>"; echo "</tr>"; } echo "</tbody></table>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (lab_tblcategories) geändert werden. Die Abb.4.5.4, Abb.4.5.5 und Abb.4.5.6 zeigen den Ablauf, um einen Datensatz in die Tabelle (lab_tblcategories) zu ändern.
Abb. 4.5.4 Kategorie-Tabellenformular für die Änderung eines Datensatzes (labeditcategories.php)
Abb. 4.5.5 Kategorie-Formular für die Änderung eines Datensatzes (labeditcategories.php)
Abb. 4.5.6 Kategorie-Tabellenformular nach der Änderung eines Datensatzes (labeditcategories.php)
Der Inhalt der Datei (labeditcategories.php)
<?php session_start(); if(isset($_POST['send'])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $sqlstr = "update lab_tblcategories set " . " name = '" . $_POST["name"] . "'," . " link = '" . $_POST["link"] . "'," . " activ = '" . $activ . "'," . " description = '" . $_POST["description"] . "'" . " where id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "The record has not been changed!"; echo "</div>"; echo "</div></div>"; } mysql_free_result($res); } if (isset($_POST["selectID"])) { $sqlstr = "select * from lab_tblcategories where id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-6'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Edit Category - Form</h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=EditCategories'>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Id:</label>"; echo "<input type='text' name='id' class='form-control' value='" . $_POST["selectID"] . "' disabled />"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Name:</label>"; echo "<input type='text' name='name' class='form-control' value='".$row['name']."'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Link:</label>"; echo "<input type='text' name='link' class='form-control' value='".$row['link']."'>"; echo "</div>"; if ($row['activ'] ==1){ echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ' checked>"; echo "</div>"; } else { echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ'>"; echo "</div>"; } echo "<div class='form-group'>"; echo "<label class='control-label'>Description:</label>"; echo "<textarea name='description' class='form-control' data-role='textarea'>".$row['description']."</textarea>"; echo "</div>"; echo "<div class='form-group'>"; echo "<input type='hidden' name='oripn' value='" . $_POST["selectID"] . "' />"; echo "<button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-edit'></span> Edit the record</button>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } else { display_edit_categories(); } function display_edit_categories(){ $sqlstr = "select * from lab_tblcategories ORDER BY id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Edit the database: <small>lab_tblcategories</small></h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=EditCategories'>"; echo "<table class='table'>"; echo "<thead>"; echo "<tr><th>Id</th>"; echo "<th>Name</th>"; echo "<th>Link</th>"; echo "<th>Activ</th>"; echo "<th>Description</th>"; echo "<th>Select</th>"; echo "</tr>"; echo "</thead><tbody>"; $n=1; while ($row = mysql_fetch_assoc($res)) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td>" . $row["name"] . "</td>"; echo "<td>" . $row["link"] . "</td>"; echo "<td>" . $row["activ"] . "</td>"; echo "<td>" . $row["description"] . "</td>"; echo "<td><input type='checkbox' name='selectID' value='" . $row["id"] . "' data-role='checkbox'></td>"; echo "</tr>"; } echo "</tbody></table>"; echo "<button type='submit' class='btn btn-primary'> <span class='fa fa-edit'></span> View the record</button>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze aus den entsprechenden Tabellen in dem Fall (lab_tblcategories) gelöscht werden. Die Abb.4.5.7 und Abb.4.5.8 zeigen den Ablauf, um einen Datensatz aus der Tabelle (lab_tblcategories) zu löschen.
Abb. 4.5.7 Kategorie-Tabellenformular für das Löschen eines Datensatzes (labdeletecategories.php)
Abb. 4.5.8 Kategorie-Formular für das Löschen eines Datensatzes (labdeletecategories.php)
Abb. 4.5.9 Kategorie-Formular für das Löschen eines Datensatzes (labdeletecategories.php)
Der Inhalt der Datei (labdeletecategories.php)
<?php session_start(); if(isset($_POST['send'])){ $sqlstr = "delete from lab_tblcategories where id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "The record has not been changed!"; echo "</div>"; echo "</div></div>"; } mysql_free_result($res); } if (isset($_POST["selectID"])) { $sqlstr = "select * from lab_tblcategories where id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-6'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Delete Category - Form</h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=DeleteCategories'>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Id:</label>"; echo "<input type='text' name='id' class='form-control' value='" . $_POST["selectID"] . "' disabled />"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Name:</label>"; echo "<input type='text' name='name' class='form-control' value='".$row['name']."'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Link:</label>"; echo "<input type='text' name='link' class='form-control' value='".$row['link']."'>"; echo "</div>"; if ($row['activ'] ==1){ echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ' checked>"; echo "</div>"; } else { echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ'>"; echo "</div>"; } echo "<div class='form-group'>"; echo "<label class='control-label'>Description:</label>"; echo "<textarea name='description' class='form-control' data-role='textarea'>".$row['description']."</textarea>"; echo "</div>"; echo "<div class='form-group'>"; echo "<input type='hidden' name='oripn' value='" . $_POST["selectID"] . "' />"; echo "<button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-edit'></span> Delete the record</button>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } else { display_delete_categories(); } function display_delete_categories(){ $sqlstr = "select * from lab_tblcategories ORDER BY id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Delete the database: <small>lab_tblcategories</small></h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=DeleteCategories'>"; echo "<table class='table'>"; echo "<thead>"; echo "<tr><th>Id</th>"; echo "<th>Name</th>"; echo "<th>Link</th>"; echo "<th>Activ</th>"; echo "<th>Description</th>"; echo "<th>Select</th>"; echo "</tr>"; echo "</thead><tbody>"; $n=1; while ($row = mysql_fetch_assoc($res)) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td>" . $row["name"] . "</td>"; echo "<td>" . $row["link"] . "</td>"; echo "<td>" . $row["activ"] . "</td>"; echo "<td>" . $row["description"] . "</td>"; echo "<td><input type='checkbox' name='selectID' value='" . $row["id"] . "' data-role='checkbox'></td>"; echo "</tr>"; } echo "</tbody></table>"; echo "<button type='submit' class='btn btn-primary'> <span class='fa fa-edit'></span> View the record</button>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (lab_tblsubcategories) hinzugefügt werden. Die Abb.4.6.1 und Abb.4.6.2 zeigen den Ablauf, um einen Datensatz in die Tabelle (lab_tblsubcategories) hinzuzufügen.
Abb. 4.6.1 Unterkategorie-Formular für einen neuen Datensatz (labinsertsubcategories.php)
Abb. 4.6.2 Hinzugefügter Datensatz (labinsertsubcategories.php)
Der Inhalt der Datei (labinsertsubcategories.php)
<?php session_start(); if(isset($_POST['send'])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $catid = get_cgi_param ("catid", 0); if($catid){ $sqlstr = "insert lab_tblsubcategories" . "(name, catid, link, activ, description) values " . "('" . $_POST["name"] . "', " . "'" . $catid . "', " . "'" . $_POST["link"] . "', " . "'" . $activ . "', " . "'" . $_POST["description"] . "')"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num>0) { display_list_subcategories(); } else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "No record has been added to the database!"; echo "</div>"; echo "</div></div>"; } mysql_free_result($res); } else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "You must selected a category name!"; echo "</div>"; echo "</div></div>"; } }else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-6'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Insert subcategory - Form</h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=InsertSubcategories'>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputName'>Name:</label>"; echo "<input type='text' name='name' class='form-control' id='inputName' placeholder='Enter subcategory name'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputSubcategoryname'>Category name:</label>"; echo "<select name='catid' class='form-control' id='inputSubcategoryname' data-role='select'>"; $sqlstr = "SELECT id, name FROM lab_tblcategories ORDER BY name ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list ($catid, $name) = mysql_fetch_row ($res)) { echo ("<option value=\"$catid\">$name (catid: $catid)</option>\n"); } echo "</select>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputLink'>Link:</label>"; echo "<input type='text' name='link' class='form-control' id='inputLink' placeholder='Enter link'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ'><br />"; echo "<small class='text-muted'>If the entry should be active, the checkbox must be clicked!</small>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputDescription'>Description:</label>"; echo "<textarea data-role='textarea' name='description' class='form-control' id='inputDescription'></textarea>"; echo "</div>"; echo "<div class='form-group'>"; echo "<button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-send'></span> Insert the record</button>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } function display_list_subcategories(){ $sqlstr = "select * from lab_tblsubcategories ORDER BY id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>List the database: <small>lab_tblsubcategories</small></h2> </div> <div class='panel-body'>"; echo "<table class='table'>"; echo "<thead>"; echo "<tr><th>Id</th>"; echo "<th>Name</th>"; echo "<th>Catid</th>"; echo "<th>Link</th>"; echo "<th>Activ</th>"; echo "<th>Description</th>"; echo "</tr>"; echo "</thead><tbody>"; while ($row = mysql_fetch_assoc($res)) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td>" . $row["name"] . "</td>"; echo "<td>" . $row["catid"] . "</td>"; echo "<td>" . $row["link"] . "</td>"; echo "<td>" . $row["activ"] . "</td>"; echo "<td>" . $row["description"] . "</td>"; echo "</tr>"; } echo "</tbody></table>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (lab_tblsubcategories) geändert werden. Die Abb.4.6.3, Abb.4.6.4 und Abb.4.6.5 zeigen den Ablauf, um einen Datensatz in die Tabelle (lab_tblsubcategories) zu ändern.
Abb. 4.6.3 Unterkategorie-Tabellenformular für die Änderung eines Datensatzes (labeditsubcategories.php)
Abb. 4.6.4 Unterkategorie-Formular für die Änderung eines Datensatzes (labeditsubcategories.php)
Abb. 4.6.5 Unterkategorie-Tabelle nach der Änderung eines Datensatzes (labeditsubcategories.php)
Der Inhalt der Datei (labeditsubcategories.php)
<?php session_start(); if(isset($_POST['send'])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $catid = get_cgi_param ("catid", 0); if($catid){ $sqlstr = "update lab_tblsubcategories set " . " name = '" . $_POST["name"] . "'," . " catid = '" . $catid . "'," . " link = '" . $_POST["link"] . "'," . " activ = '" . $activ . "'," . " description = '" . $_POST["description"] . "'" . " where id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "No record has been changed!"; echo "</div>"; echo "</div></div>"; } mysql_free_result($res); }else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "You must selected a Category!"; echo "</div>"; echo "</div></div>"; } } if (isset($_POST["selectID"])) { $sqlstr = "select * from lab_tblsubcategories where id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-6'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Edit subcategory - Form</h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=EditSubcategories'>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Id:</label>"; echo "<input type='text' name='id' class='form-control' value='" . $_POST["selectID"] . "' disabled />"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Name:</label>"; echo "<input type='text' name='name' class='form-control' value='".$row['name']."'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Category name:</label>"; echo "<select name='catid' class='form-control' data-role='select'>"; $sqlstr = "SELECT id, name FROM lab_tblcategories ORDER BY name ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list ($catid, $name) = mysql_fetch_row ($res)) { echo ("<option value=\"$catid\">$name (catid: $catid)</option>\n"); } echo "</select>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Link:</label>"; echo "<input type='text' name='link' class='form-control' value='".$row['link']."'>"; echo "</div>"; if ($row['activ'] ==1){ echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ' checked>"; echo "</div>"; } else { echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ'>"; echo "</div>"; } echo "<div class='form-group'>"; echo "<label class='control-label'>Description:</label>"; echo "<textarea name='description' class='form-control' data-role='textarea'>".$row['description']."</textarea>"; echo "</div>"; echo "<div class='form-group'>"; echo "<input type='hidden' name='oripn' value='" . $_POST["selectID"] . "' />"; echo "<button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-edit'></span> Edit the record</button>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } else { display_edit_subcategories(); } function display_edit_subcategories(){ $sqlstr = "select * from lab_tblsubcategories ORDER BY id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Edit the database: <small>lab_tblsubcategories</small></h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=EditSubcategories'>"; echo "<table class='table'>"; echo "<thead>"; echo "<tr><th>Id</th>"; echo "<th>Name</th>"; echo "<th>Catid</th>"; echo "<th>Link</th>"; echo "<th>Activ</th>"; echo "<th>Description</th>"; echo "<th>Select</th>"; echo "</tr>"; echo "</thead><tbody>"; $n=1; while ($row = mysql_fetch_assoc($res)) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td>" . $row["name"] . "</td>"; echo "<td>" . $row["catid"] . "</td>"; echo "<td>" . $row["link"] . "</td>"; echo "<td>" . $row["activ"] . "</td>"; echo "<td>" . $row["description"] . "</td>"; echo "<td><input type='checkbox' name='selectID' value='" . $row["id"] . "' data-role='checkbox'></td>"; echo "</tr>"; } echo "</tbody></table>"; echo "<button type='submit' class='btn btn-primary'> <span class='fa fa-edit'></span> View the record</button>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze aus den entsprechenden Tabellen in dem Fall (lab_tblsubcategories) gelöscht werden. Die Abb.4.6.6 und Abb.4.6.7 zeigen den Ablauf, um einen Datensatz aus der Tabelle (lab_tblsubcategories) zu löschen.
Abb. 4.6.6 Unterkategorie-Tabellenformular für das Löschen eines Datensatzes (labdeletesubcategories.php)
Abb. 4.6.7 Unterkategorie-Formular für das Löschen eines Datensatzes (labdeletesubcategories.php)
Abb. 4.6.8 Unterkategorie-Formular für das Löschen eines Datensatzes (labdeletesubcategories.php)
Der Inhalt der Datei (labdeletesubcategories.php)
<?php session_start(); if(isset($_POST['send'])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $catid = get_cgi_param ("catid", 0); if($catid){ $sqlstr = "delete from lab_tblsubcategories where id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "No record has been added to the database!"; echo "</div>"; echo "</div></div>"; } mysql_free_result($res); } else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "You must selected a Category!"; echo "</div>"; echo "</div></div>"; } } if (isset($_POST["selectID"])) { $sqlstr = "select * from lab_tblsubcategories where id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-6'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Delete subcategory - Form</h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=DeleteSubcategories'>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Id:</label>"; echo "<input type='text' name='id' class='form-control' value='" . $_POST["selectID"] . "' disabled />"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Name:</label>"; echo "<input type='text' name='name' class='form-control' value='".$row['name']."'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Category name:</label>"; echo "<select name='catid' class='form-control' data-role='select'>"; $sqlstr = "SELECT id, name FROM lab_tblcategories ORDER BY name ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list ($catid, $name) = mysql_fetch_row ($res)) { echo ("<option value=\"$catid\">$name (catid: $catid)</option>\n"); } echo "</select>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Link:</label>"; echo "<input type='text' name='link' class='form-control' value='".$row['link']."'>"; echo "</div>"; if ($row['activ'] ==1){ echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ' checked>"; echo "</div>"; } else { echo "<div class='form-group'>"; echo "<label>Activ: </label>"; echo "<input type='checkbox' name='activ'>"; echo "</div>"; } echo "<div class='form-group'>"; echo "<label class='control-label'>Description:</label>"; echo "<textarea name='description' class='form-control' data-role='textarea'>".$row['description']."</textarea>"; echo "</div>"; echo "<div class='form-group'>"; echo "<input type='hidden' name='oripn' value='" . $_POST["selectID"] . "' />"; echo "<button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-edit'></span> Delete the record</button>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } else { display_delete_subcategories(); } function display_delete_subcategories(){ $sqlstr = "select * from lab_tblsubcategories ORDER BY id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Delete the database: <small>lab_tblsubcategories</small></h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=DeleteSubcategories'>"; echo "<table class='table'>"; echo "<thead>"; echo "<tr><th>Id</th>"; echo "<th>Name</th>"; echo "<th>Catid</th>"; echo "<th>Link</th>"; echo "<th>Activ</th>"; echo "<th>Description</th>"; echo "<th>Select</th>"; echo "</tr>"; echo "</thead><tbody>"; $n=1; while ($row = mysql_fetch_assoc($res)) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td>" . $row["name"] . "</td>"; echo "<td>" . $row["catid"] . "</td>"; echo "<td>" . $row["link"] . "</td>"; echo "<td>" . $row["activ"] . "</td>"; echo "<td>" . $row["description"] . "</td>"; echo "<td><input type='checkbox' name='selectID' value='" . $row["id"] . "' data-role='checkbox'></td>"; echo "</tr>"; } echo "</tbody></table>"; echo "<button type='submit' class='btn btn-primary'> <span class='fa fa-edit'></span> View the record</button>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (lab_tblarticles) hinzugefügt werden. Die Abb.4.7.1 und Abb.4.7.2 zeigen den Ablauf, um einen Datensatz in die Tabelle (lab_tblarticles) hinzuzufügen.
Abb. 4.7.1 Artikel-Formular für einen neuen Datensatz (labinsertarticles.php)
Abb. 4.7.2 Hinzugefügter Datensatz (labinsertarticles.php)
Der Inhalt der Datei (labinsertarticles.php)
<?php session_start(); if(isset($_POST['send'])){ $subcatid = get_cgi_param ("subcatid", 0); $number = $_POST['number']; $name = $_POST['name']; $price = $_POST['price']; $description = $_POST['description']; $modified = date('Y-m-d', strtotime(str_replace('.', '-', $_POST['modified']))); $file = $_FILES['pic']['name']; // Dies hab ich noch nicht getestet, da ich den Namen immer nach datum und user id abgespeichert hab. $file = str_replace(" ", "_", "$file"); $file = htmlentities($file); // Mit leerzeichen -> _ hab ich auch noch nicht getestet, sollte aba klappen $file_type = GetImageSize($_FILES['pic']['tmp_name']); if ( (($_FILES["pic"]["type"] == "image/gif") || ($_FILES["pic"]["type"] == "image/jpeg") || ($_FILES["pic"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 2048000) ) { // Dateitype nur gif, jpeg und png und max. Größe in bytes move_uploaded_file($_FILES['pic']['tmp_name'], "uploads/temp-$file"); $file = "uploads/temp-$file"; $target = "uploads/$file"; $max_width = "800"; //Breite ändern $max_height = "800"; //Höhe ändern $quality = "90"; //Qualität ändern (max. 100) $src_img = imagecreatefromjpeg($file); $picsize = getimagesize($file); $src_width = $picsize[0]; $src_height = $picsize[1]; if($src_width > $src_height){ if($src_width > $max_width){ $convert = $max_width/$src_width; $dest_width = $max_width; $dest_height = ceil($src_height*$convert); } else { $dest_width = $src_width; $dest_height = $src_height; } } else { if($src_height > $max_height) { $convert = $max_height/$src_height; $dest_height = $max_height; $dest_width = ceil($src_width*$convert); } else { $dest_height = $src_height; $dest_width = $src_width; } } $dst_img = imagecreatetruecolor($dest_width,$dest_height); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height); imagejpeg($dst_img, "$target", $quality); $sqlstr="INSERT INTO lab_tblarticles(number, name, pic, subcatid, modified, price, description) VALUES('$number', '$name', '$file', '$subcatid', '$modified', '$price', '$description')";$res = mysql_query($sqlstr) or die ("erroror inserting data ".mysql_error()); $num = mysql_affected_rows(); if ($num>0) { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkgreen fg-white'>"; echo "record has been added to the database!"; echo "</div>"; echo "</div></div>"; } else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkgreen fg-white'>"; echo "No record has been added to the database!"; echo "</div>"; echo "</div></div>"; } mysql_free_result($res); } else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkgreen fg-white'>"; echo "File types may only be gif, jpeg or png and the picture may not be larger than 2MB!"; echo "</div>"; echo "</div></div>"; } display_list_articles(); }else { $sqlstr = "select * from lab_tblsubcategories"; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-6'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Insert article - Form</h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=InsertArticles'>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputNumber'>Number:</label>"; echo "<input type='text' name='number' class='form-control' id='inputNumber' placeholder='Enter article number'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputName'>Name:</label>"; echo "<input type='text' name='name' class='form-control' id='inputName' placeholder='Enter article name'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputPrice'>Price:</label>"; echo "<input type='text' name='price' class='form-control' id='inputPrice' placeholder='Enter article price'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputSubcategory'>Subcategory name:</label>"; echo "<select name='subcatid' class='form-control' id='inputSubcategory' data-role='select'>"; $sqlstr = "SELECT id, name FROM lab_tblsubcategories ORDER BY name ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list ($subcatid, $name) = mysql_fetch_row ($res)) { echo ("<option value=\"$subcatid\">$name (subatid: $subcatid)</option>\n"); } echo "</select>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputDate'>Date:</label>"; echo "<input type='text' name='modified' class='form-control' id='inputDate' data-format='%d %B %Y'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label' for='inputDescription'>Description:</label>"; echo "<textarea name='description' class='form-control' id='inputDescription' data-role='textarea'></textarea>"; echo "</div>"; echo "<div class='form-group'>"; echo "<input type='file' name='pic' data-role='file' data-caption='Choose file' required /></p>"; echo "<button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-send'></span> Insert the record</button>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } function display_list_articles(){ $sqlstr = "select * from lab_tblarticles ORDER BY id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>List the database: <small>lab_tblarticles</small></h2> </div> <div class='panel-body'>"; echo "<table class='table'>"; echo "<thead>"; echo "<tr><th>Id</th>"; echo "<th>Number</th>"; echo "<th>Name</th>"; echo "<th>Subcatid</th>"; echo "<th>Date</th>"; echo "<th>Pic</th>"; echo "<th>Price</th>"; echo "<th>Description</th>"; echo "<th>Select</th>"; echo "</tr>"; echo "</thead><tbody>"; while ($row = mysql_fetch_assoc($res)) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td>" . $row["number"] . "</td>"; echo "<td>" . $row["name"] . "</td>"; echo "<td>" . $row["subcatid"] . "</td>"; echo "<td>" . date('d.m.Y', strtotime($dsatz["modified"])) . "</td>"; echo "<td>" . $row["price"] . " €</td>"; echo "<td>" . $row["description"] . "</td>"; echo "<td>" . "<img style='float: left; margin-right: 25px; margin-bottom: 10px; width:50px; height:50px;' src='uploads/" . $row['pic'] ."'></td>"; echo "</tr>"; } echo "</tbody></table>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (lab_tblarticles) geändert werden. Die Abb.4.7.3, Abb.4.7.4 und Abb.4.7.5 zeigen den Ablauf, um einen Datensatz in die Tabelle (lab_tblarticles) zu ändern.
Abb. 4.7.3 Artikel-Tabellenformular für die Änderung eines Datensatzes (labeditarticles.php)
Abb. 4.7.4 Artikel-Formular für die Änderung eines Datensatzes (labeditarticles.php)
Abb. 4.7.5 Artikel-Tabelle nach der Änderung eines Datensatzes (labeditarticles.php)
Der Inhalt der Datei (labeditarticles.php)
<?php session_start(); if(isset($_POST['send'])){ $subcatid = get_cgi_param ("subcatid", 0); $number = $_POST['number']; $name = $_POST['name']; $price = $_POST['price']; $description = $_POST['description']; $modified = date('Y-m-d', strtotime(str_replace('.', '-', $_POST['modified']))); $file = $_FILES['pic']['name']; // Dies hab ich noch nicht getestet, da ich den Namen immer nach datum und user id abgespeichert hab. $file = str_replace(" ", "_", "$file"); $file = htmlentities($file); // Mit leerzeichen -> _ hab ich auch noch nicht getestet, sollte aba klappen $file_type = GetImageSize($_FILES['pic']['tmp_name']); if ( (($_FILES["pic"]["type"] == "image/gif") || ($_FILES["pic"]["type"] == "image/jpeg") || ($_FILES["pic"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 2048000) ) { // Dateitype nur gif, jpeg und png und max. Größe in bytes move_uploaded_file($_FILES['pic']['tmp_name'], "uploads/temp-$file"); $file = "uploads/temp-$file"; $target = "uploads/$file"; $max_width = "800"; //Breite ändern $max_height = "800"; //Höhe ändern $quality = "90"; //Qualität ändern (max. 100) $src_img = imagecreatefromjpeg($file); $picsize = getimagesize($file); $src_width = $picsize[0]; $src_height = $picsize[1]; if($src_width > $src_height){ if($src_width > $max_width){ $convert = $max_width/$src_width; $dest_width = $max_width; $dest_height = ceil($src_height*$convert); } else { $dest_width = $src_width; $dest_height = $src_height; } } else { if($src_height > $max_height) { $convert = $max_height/$src_height; $dest_height = $max_height; $dest_width = ceil($src_width*$convert); } else { $dest_height = $src_height; $dest_width = $src_width; } } $dst_img = imagecreatetruecolor($dest_width,$dest_height); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height); imagejpeg($dst_img, "$target", $quality); $sqlstr = "update lab_tblarticles set " . " number = '" . $_POST["number"] . "'," . " name = '" . $_POST["name"] . "'," . " pic = '" . $file . "'," . " subcatid = '" . $subcatid. "'," . " modified = '" . $modified. "'," . " price = '" . $_POST["price"] . "'," . " description = '" . $_POST["description"] . "'" . " where id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("erroror inserting data ".mysql_error()); $num = mysql_affected_rows($res); if ($num>0) { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkgreen fg-white'>"; echo "record has been added to the database!"; echo "</div>"; echo "</div></div>"; } else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "No record has been added to the database!"; echo "</div>"; echo "</div></div>"; } } else { echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='bg-darkred fg-white'>"; echo "No record has been added to the database!"; echo "</div>"; echo "</div></div>"; } mysql_free_result($res); } if (isset($_POST["selectID"])) { $sqlstr = "select * from lab_tblarticles where id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-6'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Edit article - Form</h2> </div> <div class='panel-body'>"; echo "<form method='post' action='".$url."?section=EditArticles' enctype='multipart/form-data'>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Id:</label>"; echo "<input type='text' name='id' class='form-control' value='" . $_POST["selectID"] . "' disabled />"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Number:</label>"; echo "<input type='text' name='number' class='form-control' value='".$row['number']."'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Name:</label>"; echo "<input type='text' name='name' class='form-control' value='".$row['name']."'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Subcategory name:</label>"; echo "<select name='subcatid' class='form-control' data-role='select'>"; $sqlstr = "SELECT id, name FROM lab_tblsubcategories ORDER BY name ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list ($subcatid, $name) = mysql_fetch_row ($res)) { echo ("<option value=\"$subcatid\">$name (subcatid: $subcatid)</option>\n"); } echo "</select>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Date:</label>"; echo "<input type='text' name='modified' class='form-control' value='".$row['modified']."' data-role='calendarpicker' data-format='%d %B %Y'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Price:</label>"; echo "<input type='text' name='price' class='form-control' value='".$row['price']."'>"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Image:</label>"; echo "<img style='float: left; margin-right: 25px; margin-bottom: 10px; width:50px; height:50px;' src='" . $row['pic'] ."'>"; echo "<input type='file' name='pic' placeholder='load image' required />"; echo "</div>"; echo "<div class='form-group'>"; echo "<label class='control-label'>Description:</label>"; echo "<textarea name='description' class='form-control' data-role='textarea'>".$row['description']."</textarea>"; echo "</div>"; echo "<div class='form-group'>"; echo "<input type='hidden' name='oripn' value='" . $_POST["selectID"] . "' />"; echo "<button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-edit'></span> Edit the record</button>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); }else { display_edit_articles(); } function display_edit_articles(){ $sqlstr = "select * from lab_tblarticles ORDER BY id"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); echo "<div id='page-wrapper'><div class='container-fluid'>"; echo "<div class='row'> <div class='col-md-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Edit the database: <small>lab_tblarticles</small></h2> </div> <div class='panel-body'>"; echo "<form method='post' enctype='multipart/form-data' action='".$url."?section=EditArticles'>"; echo "<table class='table'>"; echo "<thead>"; echo "<tr><th>Id</th>"; echo "<th>Number</th>"; echo "<th>Name</th>"; echo "<th>Subcatid</th>"; echo "<th>Date</th>"; echo "<th>Pic</th>"; echo "<th>Price</th>"; echo "<th>Description</th>"; echo "<th>Select</th>"; echo "</tr>"; echo "</thead><tbody>"; while ($row = mysql_fetch_assoc($res)) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td>" . $row["number"] . "</td>"; echo "<td>" . $row["name"] . "</td>"; echo "<td>" . $row["subcatid"] . "</td>"; echo "<td>" . date('d.m.Y', strtotime($row["modified"])) . "</td>"; echo "<td><img style='float: left; margin-right: 25px; margin-bottom: 10px; width:50px; height:50px;' src='" . $row['pic'] ."'></td>"; echo "<td>" . $row['price'] . "</td>"; echo "<td>" . $row["description"] . "</td>"; echo "<td><input type='checkbox' name='selectID' value='" . $row["id"] . "' data-role='checkbox'></td>"; echo "</tr>"; } echo "</tbody></table>"; echo "<button type='submit' class='btn btn-primary'> <span class='fa fa-edit'></span> View the record</button>"; echo "</form>"; echo "</div>"; echo "</div>"; echo "</div></div>"; echo "</div></div>"; mysql_free_result($res); } ?>