Vorlesungen
  Download     DBS     Sprachen     Oberflächen     Impressum     Datenschutz  
1. Sem
2. Sem
3. Sem
4. Sem
Entw. von multimedialen Anwendungen
Web-Technologien
Webprogrammierung
5. Sem
Wahlpflicht-SoSe
Wahlpflicht-WiSe
IEA-2019
Projektwochen
Allgemein:
Startseite
Vorlesungen
Labore
Sinnvolle Programme
Lineare Regression
GUI-Entwurfsarbeit
Single-Format
Design Pattern-Termine
Observer1
Bsp2
Json-Array
Json-Dialogelemente
Webtechnologien
';    $s.=" ' . PHP_EOL;    $s.=' ' . PHP_EOL;    $s.=" ' . PHP_EOL;    $s.=' ' . PHP_EOL;    $s.=' ' . PHP_EOL;    $s.=' ' . PHP_EOL;    $s.=' ' . PHP_EOL;   $s.=' ' . PHP_EOL;   $s.=' ' . PHP_EOL;   $s.='' . PHP_EOL;    return $s;   }  } ?> ' + nl;  if (str_numberDefinition.length>0) {   s +=' ' + nl;  }  for(var i in captions){   let scaption = captions[i];   let sfirst = captions[i].substring(0,1).toUpperCase();   s +=' ' + nl;  }  if (str_calledit!='') {   s +=' ' + nl;  }  if (str_calldelete!='') {   s +=' ' + nl;  }  s +='' + nl;  for (let i in objs) {   s +='' + nl;   if (str_numberDefinition.length>0) {    s +=' ' + nl;   }   let obj = objs[i];   for(var j in obj){    //alert(j);    s +=' ' + nl;   }   if (str_calledit!='') {    s+=' ' + nl;   }   if (str_calldelete!='') {    s+=' ' + nl;   }   s +='' + nl;  }  s +='

Amacon mit PHP und MySQL

BspAmacon.php

Customer.php

CustomerDB.php

dbs.txt

createTable.js

AufgabeEdit.php

updateEdit.php

updateEditAjax.php

aufgabeDelete.php

updateDelete.php

AufgabeNew.php

updateNew.php




BspAmacon.php


 
   PHP-Beispiel 1 
  
  
  
 

 


 

Amacon

 
   ";  echo $s; ?>


Customer.php

lastname . ', ' . $this->firstname;
  }


  public function createTableRow($nr) {
   $nr1 = $nr+1;
   $s='
" . $nr1 . '' . $this->pindex . '
" . $this->cnr . '
' . $this->lastname . '' . $this->firstname . '' . $this->street . '' . $this->birthday . '' . ' ' .    '' . ' ' .    '


CustomerDB.php

connect_error)  {
   die('Connection failded: ' . $conn->connect_error);
  }
  return $conn;
 }

 function loadCustomersFromDB() {
  $arr = array();
  $conn = getConnection();
  if ($conn->connect_error)  {
   return $arr;
  }
  $sql = 'SELECT PINDEX, CNR, LASTNAME, FIRSTNAME, STREET, BIRTHDAY '
  . ' FROM customer';
  $result = $conn->query($sql);
  if ($result) {
   while($row=$result->fetch_array()) {
    $customer = new Customer();
    $customer->pindex=intval($row['PINDEX']);
    $customer->cnr=intval($row['CNR']);
    $customer->lastname=$row['LASTNAME'];
    $customer->firstname=$row['FIRSTNAME'];
    $customer->street=$row['STREET'];
    $customer->birthday=$row['BIRTHDAY'];
    $arr[] = $customer;
   }
  }
  return $arr;
 }  // loadCustomersFromDB

 function loadCnrCustomersFromDB($pindex) {
  $arr = array();
  $conn = getConnection();
  if ($conn->connect_error)  {
   return $arr;
  }
  $sql = 'SELECT CNR FROM customer  WHERE pindex!= ' . $pindex;
  $result = $conn->query($sql);
  if ($result) {
   while($row=$result->fetch_array()) {
    $customercnr = new CustomerCnr ();
    $customercnr->cnr=intval($row['CNR']);
    //echo $row['CNR'] . '
';     $arr[] = $customercnr;    }   }   return $arr;  } // loadCustomersFromDB  function loadCustomerFromDB($pindex) {   $customer = new Customer();   $conn = getConnection();   if ($conn->connect_error) {    return $customer;   }   $sql = 'SELECT PINDEX, CNR, LASTNAME, FIRSTNAME, STREET, BIRTHDAY '   . ' FROM customer WHERE pindex=' . $pindex;   $result = $conn->query($sql);   if ($result) {    while($row=$result->fetch_array()) {     $customer->pindex=intval($row['PINDEX']);     $customer->cnr=intval($row['CNR']);     $customer->lastname=$row['LASTNAME'];     $customer->firstname=$row['FIRSTNAME'];     $customer->street=$row['STREET'];     $customer->birthday=$row['BIRTHDAY'];    }   }   return $customer;  } // loadCustomersFromDB  function updateCustomerDB($customer) {   $conn = getConnection();   if ($conn->connect_error) {    return $arr;   }   $sql = 'UPDATE customer ' .   ' SET '.   ' CNR=' . $customer->cnr. ', ' .   ' LASTNAME=' . quoted($customer->lastname) . ', ' .   ' FIRSTNAME=' . quoted($customer->firstname) . ', ' .   ' STREET=' . quoted($customer->street) . ', ' .   ' BIRTHDAY=' . quoted($customer->birthday) .   " WHERE PINDEX=$customer->pindex ";   echo $sql;   $result = $conn->query($sql);   if ($result) {    echo "ok";   }   else {    echo $conn->error; // 'fehler ' . $result;   }  } // updateCustomerDB  function deleteCustomerDB($pindex) {   $conn = getConnection();   if ($conn->connect_error) {    return 'connect-Error';   }   //echo $sql . '
';   if ($conn->query($sql)) {    return 'ok';   }   else {    return $conn->error; // 'fehler ' . $result;   }  } // deleteCustomerDB  function getDBSequence() {   $conn = getConnection();   if ($conn->connect_error) {    return 0;   }   $sql = 'UPDATE sequence SET id=LAST_INSERT_ID(id+1);';   $result = $conn->query($sql);   if ( $result ){    $sql ='SELECT * FROM `sequence` '; // SELECT LAST_INSERT_ID()';    $result = $conn->query($sql);    if ( $result ){     while ( $row = $result->fetch_array() ) {      $sequence = intval($row[0]) ;     } // while    } // if   }   else {    // die('SQL-Anweisung gescheitert');    $sequence = 0;   }   return $sequence;  }  function insertCustomerDB($customer) {   $customers = loadCustomersFromDB();   foreach ($customers as $customerloop) {    if ($customerloop->cnr==$customer->cnr) {     echo 'Fehler: die cnr ist schon vorhanden';     return false;    }   }   $sql = 'INSERT INTO customer(PINDEX, CNR, LASTNAME, FIRSTNAME, STREET, BIRTHDAY)' .   ' VALUES( ' .   ' ' . $customer->pindex . ', ' .   ' ' . $customer->cnr . ', ' .   ' ' . quoted($customer->lastname) . ', ' .   ' ' . quoted($customer->firstname) . ', ' .   ' ' . quoted($customer->street) . ', ' .   ' ' . quoted($customer->birthday) .   ' )';   $conn = getConnection();   if ($conn->connect_error) {    return $conn->error; // 'fehler ' . $result;   }   //echo $sql . '
';   if ($conn->query($sql)) {    return 'ok';   }   else {    return $conn->error; // 'fehler ' . $result;   }  } // insertCustomerDB ?>

dbs.txt


CREATE TABLE `CUSTOMER` (
  `PINDEX`  INTEGER  NOT NULL ,
  `CNR`  INTEGER  DEFAULT 0  NOT NULL  UNIQUE,
  `LASTNAME`  VARCHAR(50)  DEFAULT '',
  `FIRSTNAME`  VARCHAR(50)  DEFAULT '',
  `STREET`  VARCHAR(50)  DEFAULT '',
  `BIRTHDAY`  VARCHAR(10)  DEFAULT '2018-01-01',

  CONSTRAINT `PK_EMPLOYEE`  PRIMARY KEY (`PINDEX`)
);

Insert into customer(pindex,  cnr, lastname, firstname, street,  birthday)
Values(11, 12345, 'Meier', 'Hans', 'Friedrichstrasse 55', '2018-03-14');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(12, 54321,'Schulze', 'Susanne', 'Langgasse 4a', '2011-03-07');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(13, 234, 'Brandter', 'Torsten', 'Marktstrasse 5', '2018-03-07');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(14,42, 'Dent', 'Arthur', 'Magarethea Weg 12', '1996-08-07');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(15, 142, 'Braun', 'Werner', 'Nasa 1969', '1969-07-20');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(16, 145, 'Brandt', 'Willi', 'Kastanieallee 12a', '1971-02-10');

Insert into customer(pindex,  cnr, lastname, firstname, street,  birthday)
Values(17, 345, 'Schmitt', 'Dorethea', 'Martkstrasse 3', '2001-12-24');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(18, 11, 'Schwarzenau', 'Paul', 'Kreuzerweg 12a', '2001-04-17');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(19, 55, 'Gisin', 'Nicola', 'Springerallee 1', '1999-12-24');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(20, 123, 'Genius', 'Chantal', 'Hallenser Strasse 3', '1991-02-10');

Insert into customer(pindex,  cnr, lastname, firstname, street,  birthday)
Values(21, 77, 'Schoen', 'Jaqueline', 'Einkaufsallee 123', '1991-02-11');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(22, 14, 'Schwarz', 'Hans-Georg', 'Lange Strasse 3', '1985-06-27');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(23, 35, 'Maurer', 'Fritz', 'Handwerkerweg 5', '1979-02-29');

Insert into customer(pindex, cnr, lastname, firstname, street,  birthday)
Values(24, 113, 'Bosch', 'Hieronymus', 'Kunstweg 42', '1998-05-11');

Insert into customer(pindex,  cnr, lastname, firstname, street,  birthday)
Values(25, 57, 'Brandtner', 'Andrea', 'Rosenweg 2', '2001-02-03');

  CREATE TABLE sequence (id INT NOT NULL);
  INSERT INTO sequence VALUES (30);
  
    UPDATE sequence SET id=LAST_INSERT_ID(id+1);
    SELECT LAST_INSERT_ID();


createTable.js


// ' + nl;
 s +='
' + str_numberDefinition + '' + sfirst + scaption.substring(1,scaption.length) + '' + '-' + '' + '-' + '
' + (i+1) + '' + obj[j] + '' + '' + '' + '' + '
' + nl;  return s; } // ]]>


AufgabeEdit.php


 
   Bearbeiten eines Customers 
  
  
  
 

 



 

Edit an address

 
pindex);   //echo count($cnrs) . '
';   $hiddencnrs = json_encode($cnrs );  ?>  
 Inputs for an address  
 
 
 
 
 
 
 
 
 
   
 
 
 
         
 
 
 
 Wrong Parameter in variable pindex'; } ?>


updateEdit.php

pindex = $pindex;
  $customer->cnr= $cnr;
  $customer->lastname = $_GET['lastname'];
  $customer->firstname = $_GET['firstname'];
  $customer->street = $_GET['street'];
  $customer->birthday= $_GET['birthday'];

  updateCustomerDB($customer);
 }
 else {
  echo 'Fehler';
 }

 header('location: bspAmacon.php');
 exit(0);


?>

updateEditAjax.php

pindex = $pindex;
  $customer->cnr= $cnr;
  $customer->lastname = $_GET['lastname'];
  $customer->firstname = $_GET['firstname'];
  $customer->street = $_GET['street'];
  $customer->birthday= $_GET['birthday'];

  $result = updateCustomerDB($customer);
  echo $result;
 }
 else {
  echo 'Fehlerhafte Parameter';
 }

// header('location: bspAmacon.php');
// exit(0);


?>



aufgabeDelete.php


 
   Delete a customer 
  
  
  


  
 


 

Delete an address

 
 
 Delete an address  
 
 
 
 
 
 
 
 
 
pindex; ?>
cnr; ?>
lastname; ?>
firstname; ?>
street; ?>
birthday; ?>
 
 
 
 Do you really want to delete the dataset, pindex=" . $customer->pindex . "?"; ?>
Wrong Parameter in variable pindex'; } ?>


updateDelete.php


=0) {
   echo '

value for pindexDelete: ' . $pindex . '

';    deleteCustomerDB($pindex);    header('location: bspAmacon.php');    exit(1);   }   else {    echo '

Wrong value for pindexDelete: ' . $pindex . '

';   }  } // if (is_numeric($str_pindex)) {  else {   echo '

Wrong parameter for pindexDelete: ' . $str_pindexDelete . '

';  } ?>


AufgabeNew.php


 
   New customer 
  
  
  

  

 

';
 $hiddencnrs = json_encode($cnrs );
?>


 

Insert a new address

 
 
 Inputs for an address  
 
 
 
 
 
 
 
 
   




updateNew.php


=0) {
   $customer = new Customer();
   $customer->pindex = getDBSequence();
   $customer->cnr = $_GET['cnr'];
   $customer->lastname = $_GET['lastname'];
   $customer->firstname = $_GET['firstname'];
   $customer->street = $_GET['street'];
   $customer->birthday= $_GET['birthday'];
   if (insertCustomerDB($customer)) {
    //echo 'ok';
    header('location: bspAmacon.php');
    exit(1);
   }
   else {
    echo 'Fehler beim Eintragen eines neuen Datensatzes';
   }
  }
 }  // if (is_numeric($str_customno)) {
 else {
  echo 'Fehler:  CNR ist nicht numerisch';
 }
?>

Datenbank Amacon