Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Voting Script

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi.

Can someone tell me, what I'm doing wrong with this *@#$ voting script?

There are three items, you can vote for.

The script should read the data in "Umfrage.txt" line by line into $Vote1, $Vote2, $Vote3, and increase the Item the User has voted for by 1. Than it should rewrite the new data line by line to "Umfrage.txt". But theres something wrong with this writing routine, because always, when I open "Umfrage.txt" there is only s*** in it.

Heres the Script:

<script language=&quot;PHP&quot;>

$dateiname = &quot;Umfrage.txt&quot;;

$Vote1 = 0;

$Vote2 = 0;

$Vote3 = 0;

if(file_exists($dateiname))

{

$datei = fopen($dateiname, &quot;r&quot;);

if ($datei)

{

$Vote1 = fgets($datei, 255);

$Vote2 = fgets($datei, 255);

$Vote3 = fgets($datei, 255);

fclose($datei);

}

}

if ($id = 1)

{

$Vote1 = $Vote1 + 1;

}

elseif ($id = 2)

{

$Vote2 = $Vote2 + 1;

}

elseif ($id = 3)

{

$Vote3 = $Vote3 + 1;

}

$datei = fopen($dateiname, &quot;w&quot;);

if ($datei)

{

fputs($datei, &quot;$Vote1\n$Vote2\n$Vote3\n&quot;);

fclose($datei);

}

echo &quot;$Vote1 $Vote2 $Vote3&quot;;

echo &quot;<div Align='Center'>Ihre Abstimmung wurde erfolgreich übermittelt.<br><a href='javascript:history.back()'>Zurück</a></div>&quot;;



</script>


P.S.: Sorry for my bad English, but I'm a german, and newbie :)
 
change the read-from-file lines to:

$Vote1 = trim(fgets($datei, 255));
$Vote2 = trim(fgets($datei, 255));
$Vote3 = trim(fgets($datei, 255));

and your conditions should read:

if($id==1) ...

etc. (notice the doubled equal sign)

and make sure $id is available ;-)

PS: the trim() function strips the newline character which was still attached to the $Vote variables in your code fragment. It's not a lie if YOU believe it ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top