User Tools

Site Tools


kurs:php12_3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

kurs:php12_3 [2014/09/10 21:22] (current)
Line 1: Line 1:
 +====== Bestell-Formular ======
 +Am Anfang fur ich ein php-Dokument auf, \\
 +<code php>
 +include '​..\basics\HTML.php';​
 +</​code>​
 +in dem ich die Funktionen für HTML-Kopf und HTML-Fuss definiert habe\\
  
 +<code php>
 +include '​..\basics\HTML.php';​
 +function falsch($text,​$url='​$_SERVER[PHP_SELF]'​){
 + print("<​br><​A HREF=$_url>​$text</​A>"​);​
 +}
 +
 +function frm_zeige($fehler=''​){
 + HTML_Begin("​Pizzabestellung"​);​
 + $db = ocilogon("​scott",​ "​tiger"​);​
 + $sql_select = "​select * from pizza";​
 + $result = ociparse($db,​ $sql_select);​
 + ociexecute($result) or die();
 + if ($fehler) {
 +     print("<​font color=red><​b>​Folgende Fehler sind aufgetreten:</​B><​ul><​li>"​);​
 + print(implode('</​li><​li>',​$fehler));​
 + print('</​li></​ul></​font><​br>'​);​
 + }
 + print("<​form method=post action=$_SERVER[PHP_SELF]>​
 + <input type='​hidden'​ name='​test'​ value='​1'>​
 + <table border='​0'​ cellspacing='​0'​ cellpadding='​5'>​
 +     <​th>​Pizzabestellung</​th>"​);​
 + while(ocifetchinto($result,​$a_pizzen)){
 + print("<​tr>​
 + <​td><​input type='​checkbox'​ name='​Pizza[]'​ value=$a_pizzen[0]>​ $a_pizzen[1]</​td>​
 + <​td>​$a_pizzen[2]</​td>​
 + </​tr>"​);​
 + }
 + print("<​tr>​
 + <td valign=top>​Kunde</​td>​
 + <​td>​
 + <​input type='​text'​ name='​Name'​ value='​Name'><​br>​
 + <​input type='​text'​ name='​Adresse'​ value='​Adresse'>​
 + </​td>​
 + <​tr>​
 + <​tr>​
 + <td valign=top>​Zahlungsmittel</​td>​
 + <​td>​
 + <​input type='​radio'​ name='​Zahlungsmittel'​ value='​Visa'​ checked>​Visa<​br>​
 + <​input type='​radio'​ name='​Zahlungsmittel'​ value='​Mastercard'>​Mastercard<​br>​
 + <​input type='​radio'​ name='​Zahlungsmittel'​ value='​American Express'>​American Express
 + </​td>​
 + <​tr>​
 + <​tr>​
 + <td colspan=2 align=right><​input type='​submit'​ name='​Submit'​ value='​bestellen'></​td>​
 +     </tr>
 + </​table>​
 + </​form>"​);​
 + HTML_End();​
 +}
 +
 +function frm_validieren(){
 + $a_fehler = array();
 + if (strlen($_POST['​Name'​])<​1 || $_POST['​Name'​]=='​Name'​) {
 + $a_fehler[]='​Name ist ein Pflichtfeld';​
 + }
 + if (strlen($_POST['​Adresse'​]<​1 || $_POST['​Adresse'​]=='​Adresse'​)) {
 + $a_fehler[]='​Adresse ist ein Pflichtfeld';​
 + }
 + if (strlen($_POST['​Pizza'​])<​1) {
 + $a_fehler[]='​Sie müssen mindestens eine Pizza bestellen';​
 + }
 + return $a_fehler;
 +}
 +
 +function frm_verarbeite(){
 + $gesamt = 0;
 + print("<​table border=0 cellspacing=0 cellspacing=2 width=250>"​);​
 + print("<​th colspan=2>​Rechnung</​th>"​);​
 + print("<​tr><​td colspan=2 bgcolor='#​cccccc'><​img src=no.gif height=1></​td></​tr>"​);​
 + foreach($_POST['​Pizza'​] as $wahl){
 + $db = ocilogon("​scott",​ "​tiger"​);​
 + $sql_wahl = "​select * from Pizza where P_Nr=$wahl";​
 + $result_2 = ociparse($db,​ $sql_wahl);
 + ociexecute($result_2) or die();
 + while(ocifetchinto($result_2,​ $auswahl)){
 + print("<​tr><​td>​$auswahl[1]</​td><​td align=right width=40>​$auswahl[2]</​td>"​);​
 + $gesamt += $auswahl[2];​
 + };
 + }
 + print("</​tr><​tr><​td colspan=2 align=right>​$gesamt</​td></​tr></​table>"​);​
 + falsch('​Ändern'​);​
 +}
 +###### ​ Main  ######
 +if(array_key_exists('​test',​$_POST)){
 + if ($a_fehler = frm_validieren()) {
 + frm_zeige($a_fehler);​
 + } else{
 + frm_verarbeite();​
 + }
 +} else {
 + frm_zeige();​
 +}
 +</​code>​
kurs/php12_3.txt · Last modified: 2014/09/10 21:22 (external edit)