Hallo alle zusammen, ich hoffe mal meine Überschrift passt soweit... In PHP arbeite ich mich gerade erst ein...
Ich rufe hier in meinem index eine Umfrage auf, vote.php. Das Problem liegt darin, dass die Werte nicht verändert werden, also $voteAntwort. Und ich bin ratlos woran es liegt bzw wie ich es hinbekommen kann, schließlich wird über $thisFile und $newVoteCount $voteAntwort angesprochen, also sollte eigentlich...
index.php
vote.php
Ich rufe hier in meinem index eine Umfrage auf, vote.php. Das Problem liegt darin, dass die Werte nicht verändert werden, also $voteAntwort. Und ich bin ratlos woran es liegt bzw wie ich es hinbekommen kann, schließlich wird über $thisFile und $newVoteCount $voteAntwort angesprochen, also sollte eigentlich...
index.php
PHP:
<?php
if(!session_id())
session_start();
session_destroy();
if(!isset($_SESSION['voted']) && isset($_POST['vote4']) && isset($voteAntwort[$_POST['vote4']]))
{
$thisFile = file_get_contents('vote.php');
$newVoteCount = $voteAntwort[$_POST['vote4']] + 1;
$thisFile = preg_replace('/\$voteAntwort\[\'('.$_POST['vote4'].')\'\](\s*)= (.*);/iU', '$voteAntwort[\'$1\']$2= '.$newVoteCount.';', $thisFile);
fwrite(fopen('vote.php', 'wb'), $thisFile);
header('Location: '.$_SERVER['REQUEST_URI']);
$_SESSION['voted'] = true;
die();
}
?>
<?php include("vote.php"); ?>
vote.php
PHP:
<?php
$voteFrage = 'Wie findet ihr das neue PartyPiczSaar?';
$voteAntwort['super'] = 0;
$voteAntwort['gut'] = 0;
$voteAntwort['ok'] = 0;
$voteAntwort['naja'] = 0;
$voteAntwort['nicht mein Ding'] = 0;
echo('<form method="post" action="'.$_SERVER['REQUEST_URI'].'">');
echo('<b><font>'.htmlentities($voteFrage).'</font></b><br /><br>');
echo('<style>form{width:140px;text-align:left;padding:10px;background: url(img/style/bg30.png);} font{font-size:12px;color:#222;} *{font: normal 96.00% "Lucida Sans Unicode",sans-serif;color:#444;} input{border:1px solid #000; background:#EEF;color:#222;}</style>');
$voteAntworten = array_sum($voteAntwort);
foreach($voteAntwort as $antwort => $votes)
{
if($voteAntworten)
$prozent = round($votes / $voteAntworten * 100, 2);
else $prozent = 0;
$antwort = htmlentities($antwort);
echo('<input type="radio" name="vote4" value="'.$antwort.'" /> '.$antwort.' ('.$prozent.' %)<br />');
}
echo('<br>'.$voteAntworten.' Leute haben abgestimmt.<br>');
echo('<br><input type="submit" action="action" value="Abstimmen" /></form>');
?>