UmfrageTabelle umfrage in der Datenbank xy anlegenentweder DOS-Eingabeaufforderung mysql> create table umfrage ( id int (10) unsigned not null auto-increment, frage varchar (255) not null default ' ', antwort1 varchar (255) not null default ' ', antwort2 varchar (255) not null default ' ', antwort3 varchar (255) not null default ' ', abstimmung1 int(10) unsigned not null default '0', abstimmung2 int(10) unsigned not null default '0', abstimmung3 int(10) unsigned not null default '0', primary key (id) ) type=myisam; oder Erstellung der Tabelle über php-Skript tabelleanlegen.php <?php include ('config.php'); $a= mysql_query("create table umfrage ( id int (10) unsigned not null auto_increment, frage varchar (255) not null default ' ', antwort1 varchar (255) not null default ' ', antwort2 varchar (255) not null default ' ', antwort3 varchar (255) not null default ' ', abstimmung1 int(10) unsigned not null default '0', abstimmung2 int(10) unsigned not null default '0', abstimmung3 int(10) unsigned not null default '0', primary key (id) ) type=myisam; "); ?> config.php <?php $server= "localhost"; $user= "root"; $passwort= "root"; $datenbank= "xy"; $verbindung= mysql_connect ($server, $user, $passwort) or die ("Es konnte keine Verbindung zum Server hergestellt werden."); mysql_select_db ($datenbank) or die ("Die Datenbank existiert nicht."); ?> styles.css h2 { font-weight: bold; font-size: 15px; text-transform: uppercase; color: #000000; line-height: 15px; font-family: verdana, arial, helvetcia } div { font-weight: bold; font-size: 10px; text-transform: uppercase; color: #039006; line-height: 15px; font-family: verdana, arial, helvetcia } input { background-color: #ffffff; border-left: 1px solid #000000; border-right: 1px solid #000000; border-top: 1px solid #000000; border-bottom: 1px solid #000000 } eingabe.php <html> <head> <title> Erstellung der Umfrage </title> <link rel= "StyleSheet" type="text/css" href= "styles.ccs"> </head> <body> <?php $a =$_GET ["submit"]; $b =$_GET ["frage"]; $c =$_GET ["antwort1"]; $d =$_GET ["antwort2"]; $e =$_GET ["antwort3"]; if (!$a) // Die if-Bedingung ist notwendig, sonst wird bei jedem Aufruf des Skripts ein leerer Datensatz erzeugt. // Wenn $a nicht vorhanden ist (es wurde nur das Skript aufgerufen und nicht auf den Button // "abschicken" geklickt) erscheint das Eingabeformular. Wird dann auf "abschicken" geklickt, erhält $a // einen Wert und die Anweisung nach else wird ausgeführt. { ?> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td> <form action = "eingabe.php" method="get"> <table cellspacing= "5"> <tr> <td> <div> Umfrage-Titel </div> </td> <td> <input type = "text" name="frage" size="26"> </td> </tr> <tr> <td> <div>Antwort1 </div> </td> <td> <input type = "text" name="antwort1" size="26"> </td> </tr> <tr> <td> <div>Antwort2 </div> </td> <td> <input type = "text" name="antwort2" size="26"> </td> </tr> <tr> <td> <div>Antwort3 </div> </td> <td> <input type = "text" name="antwort3" size="26"> </td> </tr> <tr> <td align="right" colspan="2"> <input type ="submit" name="submit" value="Umfrage abschicken"> </td> </tr> </table> </form> </td> </tr> </table> <?php } else { include ('config.php'); $f= "insert into umfrage (frage, antwort1, antwort2, antwort3) values ('$b','$c','$d','$e')"; $g= mysql_query($f); } ?> </body> </html> umfrage.php <html> <head> <title> Hier erfolgt die Abstimmung </title> <link rel= "StyleSheet" type="text/css" href= "styles.css"> </head> <body> <?php $a =$_GET ["submit"]; $b =$_GET ["frage"]; $antwort=$_GET ["antwort"]; $c =$_GET ["antwort1"]; $d =$_GET ["antwort2"]; $e =$_GET ["antwort3"]; $i =$_GET ["id"]; include ('config.php'); $y= "select id, frage, antwort1, antwort2, antwort3 from umfrage order by id desc"; $z= mysql_db_query(xy,$y); $p= mysql_fetch_row($z); //Array list($i, $b, $c, $d, $e) = $p; // Zuweisung von Variablen list-Funktion ?> <form method="get" action= "abstimmung.php"> <?php echo '<b>'; echo $b; echo '</b>'; ?> <table width="200"> <tr> <td> <div> <?php echo $c; ?> </div> </td> <td> <input type="radio" name="antwort" value="1"> </td> </tr> <tr> <td> <div> <?php echo $d; ?> </div> </td> <td> <input type="radio" name="antwort" value="2"> </td> </tr> <tr> <td> <div> <?php echo $e; ?> </div> </td> <td> <input type="radio" name="antwort" value="3"> </td> </tr> </table> <input type="hidden" name="id" value=" <?php echo $i; ?> "> <br> <input type="submit" name="submit" value="jetzt abstimmen"> </form> <form method="get" action= "zwischenergebnis.php"> <input type="hidden" name="id" value="<?php echo $i; ?>"> <input type="submit" name="submit" value="Zwischenergebnis"> </form> </body> </html> abstimmung.php <?php
|