ik krijg een error in mijn poll: Notice: Undefined index: poll in C:\server\Apache2\htdocs\in da house\test\poll.php on line 9
regel 9=
 $cookie = $_COOKIE['poll'];

hij geeft de poll wel weer en als ik heb gestemt geeft hij geen error meer!
iemand enig idee wat daar fout aan is, of wat ik er aan kan doen?

dit is het poll.php:
 <?php
include "config.php";

function showpoll()
{
  // This function is to show the question, or the answer
  
  // Cookie
  $cookie = $_COOKIE['poll'];
  
  // Check if cookie exsists
  if (empty($cookie))
  {
    // Show the last question (function)
    showlast();
  } else {
    // Check if cookie is still valid (function)
    cookiecheck($cookie);
  }
}

function showlast()
{
  // This function shows the last question and its answers
  
  // Collect the question from the DB
  $query = mysql_query("SELECT id, question FROM poll_questions ORDER BY id DESC LIMIT 0,1");
  $num = mysql_num_rows($query);
  
  if (empty($num))
  {
    echo "Fout!";
  } else {
    $question = mysql_fetch_row($query);
    
    // Start of the form
    echo "<form name=\"poll\" action=\"pollvote.php?redirect=".$_SERVER['REQUEST_URI']."\" method=\"post\">\n";
    
    // Show the question
    echo $question[1]."<br>\n";

    // Collect the answers from the DB
    $query = mysql_query("SELECT id, answer FROM poll_answers WHERE poll_id = '$question[0]' ORDER BY id");
    $num = mysql_num_rows($query);
    if (empty($num))
    {
        echo "Fout!";
    } else {
      while ($answer = mysql_fetch_row($query))
      {
        // Show the answers
        echo "<input name=\"answer\" type=\"radio\" onclick=\"document.poll.submit()\" value=\"".$answer[0]."\" id=\"poll".$answer[0]."\">\n";
        echo "<a href=\"javascript:document.poll.submit()\" onmouseover=\"document.poll.poll".$answer[0].".checked=true\">".$answer[1]."</a><br>\n";
      }
    }
    
    // Close the form
    echo "</form>";
  }
}

function cookiecheck($cookie)
{
  // This function checks if the poll_id in the cookie is the same as the poll_id from the last question
  // if so, it will show the answers, else it will show the last question

  // Collect the last poll_id FROM the DB
  $query = mysql_query("SELECT id FROM poll_questions ORDER BY id DESC LIMIT 0,1");
  $num = mysql_num_rows($query);

  if (empty($num))
  {
    echo "Fout!";
  } else {
    // Check if the last poll_id is equal to the poll_id from the cokkie
    $last = mysql_fetch_row($query);

    if ($last[0] == $cookie)
    {
      // Show the results (function)
      showresults($cookie);
    } else {
      // Show the question (function)
      showlast();
    }
  }
}

function showresults($cookie)
{
  // This function will show the results of the poll, it's seen after voting

  // Collect the question from the DB
  $query = mysql_query("SELECT id, question, total_votes FROM poll_questions WHERE id = '$cookie'");
  $num = mysql_num_rows($query);

  if (empty($num))
  {
    echo "Fout!";
  } else {
    $question = mysql_fetch_row($query);
    echo $question[1]."<br>\n";
    
    // Antwoorden ophalen
    $query = mysql_query("SELECT id, answer, votes FROM poll_answers WHERE poll_id = '$question[0]' ORDER BY id");
    $num = mysql_num_rows($query);

    if (empty($num))
    {
        echo "Fout!";
    } else {
      // Calculate percentage of 1 vote
      $vote = 100 / $question[2];
      
      // Show the answers with a image and a percentage
      while ($answer = mysql_fetch_row($query))
      {
        // Laat de antwoorden zien
        echo $answer[1] . "\n";
        // Uitrekenen hoeveel procent deze heeft
        $percent = round($vote * $answer[2]);
        echo "<br><img src=\"poll.gif\" height=\"10\" width=\"".$percent."\" alt=\"".$percent."%\" border=\"0\">&nbsp;";
        echo $percent . "%<br>\n";
      }
      echo "Totaal: ".$question[2]." stemmen\n";
    }
  }
}

showpoll();
?> 
Regel 9: $cookie = $_COOKIE['poll'];

die index die niet bestaat volgens de foutmelding is dus poll.

Er is dus geen koekje met de naam poll, je zou dus iets moeten doen als (om te controleren of het cookie wel bestaat):

if(isset($_COOKIE['poll'])){
$cookie = $_COOKIE['poll'];
}
dan geeft hij weer een error: Parse error: parse error, unexpected '{' in C:\server\Apache2\htdocs\in da house\test\poll.php on line 10
dat is deze regel: if(isset($_COOKIE['poll']){
Ik had het inmiddels al veranderd, maar ik was een ) vergeten om de if te sluiten.
Goed overnemen/typen helpt . . .

Zelf je haakjes controleren (tellen ) heb je nog meer aan! !

een ) te weinig misschien ?

edit : ok, sorry was anders

Reageren