PHP - Votingsystem, brauche Hilfe

Alexander12

Erfahrenes Mitglied
Hi.

Ich arbeite gerade an einem kleinen Votingsystem für meine Webseite. Es Basiert auf Textdokumenten. Wenn der User eine Option ausgewählt hat, schreibt das Skript in ein Textdokument 1. Der vorherige Wert wird überschrieben. Ich habe für jede Option ein Textdokument. Das auslesen ist auch schon ferig. Nun mein Problem kann ich bervor das Skript den Wert überschreibt den aktuellen Wert auslesen und +1 dazurechnen, dann den neuen Wert, anstatt immer 1 hineinschreiben? Bitte um Codeschnipsel. Danke schon Mal. :)

MfG Alexander12
 
Hmm.. Ich habe es jetzt mal so probiert.

Formular start.html:
2 Checkboxen(Namen: option1, option2), ein submit Button

Skript voting1.php:

PHP:
<?php
$gdi = $_POST["option1"];
$directx = $_POST["option2"];
$WAHL = 1;

if(option1 == true)
{
if(file_exists("gdi+.txt"))
     {
     $option_1 = file_get_contents("gdi+.txt");
	 function rechne1($option_1, $WAHL)
		 {
		 global $option_1;
		 global $WAHL;
			//$option_1 + 1;
			return $option_1 + 1;

		 }
		 rechne1();
		 echo("GDI+ - $option_1 Stimmen.");

     } 
	 else 
{
if(file_exists("gdi+.txt"))
     {
     $option_1 = file_get_contents("gdi+.txt");
     echo("GDI+ - $option_1 Stimmen.");
	 }
}
}
if(option2 == true)
{
if(file_exists("directx.txt"))
     {
     $option_2 = file_get_contents("directx.txt");
	 function rechne2($option_2, $WAHL)
		 {
		 global $WAHL;
		 global $option_2;
			//$option_1 + 1;
			return $option_2 + 1;

		 }
		 rechne2();
		 echo("DirectX - $option_1 Stimmen.");

     } 
	 else 
{
if(file_exists("directx.txt"))
     {
     $option_2 = file_get_contents("directx.txt");
     echo("DirectX - $option_1 Stimmen.");
	 }
}
}



?>
Aber da kommen immer noch Fehler ... ich weiß nicht warum :( Weiß jemand warum?

Fehler:

Notice: Undefined index: option1 in C:\WEB\Apache2\htdocs\voting\voting1.php on line 16

Notice: Undefined index: option2 in C:\WEB\Apache2\htdocs\voting\voting1.php on line 17

Notice: Use of undefined constant option1 - assumed 'option1' in C:\WEB\Apache2\htdocs\voting\voting1.php on line 20

Warning: Missing argument 1 for rechne1() in C:\WEB\Apache2\htdocs\voting\voting1.php on line 25

Warning: Missing argument 2 for rechne1() in C:\WEB\Apache2\htdocs\voting\voting1.php on line 25
GDI+ - 0 Stimmen.
Notice: Use of undefined constant option2 - assumed 'option2' in C:\WEB\Apache2\htdocs\voting\voting1.php on line 46

Warning: Missing argument 1 for rechne2() in C:\WEB\Apache2\htdocs\voting\voting1.php on line 51

Warning: Missing argument 2 for rechne2() in C:\WEB\Apache2\htdocs\voting\voting1.php on line 51
DirectX - 0 Stimmen.

MfG Alexander12

EDIT: Die Textdokumente enthalten beide den Wert 0.
 
Zurück