Übungsmaterial

PHP

Datei erste.phtml:

<html>
<head>
<title>Eine PHP Datei zum Üben</title>
</head>
<body bgcolor="yellow" >
<h1>Eine PHP Datei zum Üben</h1>

<form action="erste.phtml" >
<p>
Wie ist dein Name ?
<input type="text" name="user" >
</p>

<p>
<input type="submit" value="Ab die Post!" >
</p>
</form>

<?php
  if ( $user == "James Bond" ) {
     for( $i = 6; $i < 12; $i++ ) {
         print "<p style='font-size: $i"."pt;' >Hallo $user wie gehts zum $i-ten mal?</p>\n";
     }
  }
  print "<p> 77+88 = ";
  print 77 + 88;
  print ", 77 . 88 = ";  
  print 77 . 88;
  print ", '77' + '88' = ";
  print "77" + "88";
  print ", '77' . '88' = ";
  print "77" . "88";
  print "</p>\n";

  print "<p>Diese Seite wurde ";
  counter();
  print " mal aufgerufen";
  print "<p>Der letzte Aufruf kam von dem Rechner: $REMOTE_ADDR </p>";

 ?>

</body>
</html>

MySQL

mysql.phtml:

<html>
<head>
<title>Zugriff auf MySQL</title>
</head>
<body bgcolor="aqua" >
<h1>Zugriff auf MySQL</h1>

<?php
  $db = mysql_connect('localhost','kurs','kurs');
  print "<p>Verbunden zum Datenbank-Server</p>";

  mysql_select_db('kurs');
  print "<p>Datenbank gewählt</p>";

  $res = mysql_query( 'SELECT * FROM zaehler;' );
  print "<p>Anfrage gestellt</p>";
  print "<p>Anzahl der Zeilen = " . 
        mysql_num_rows( $res) . 
        "</p>";
  $anzahl = mysql_num_rows( $res );
  for ( $i = 0; $i < $anzahl; $i++ ) {
    print "<p>Zeile = " . 
          mysql_result( $res, $i, 0 ) .
          ", count = " .
          mysql_result( $res, $i, 1 ) .
          "</p>";
  }

  mysql_close($db);
  print "<p>Verbindung geschlossen</p>";
 ?>

</body>
</html>

© Universität Mannheim, Rechenzentrum, 1998-2002.

Heinz Kredel
Last modified: Wed Oct 2 09:55:48 CEST 2002