[PHP] Probleem met cookies i.c.m. opmaak

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Hoi,

Ik ben bezig met een poll, alles werkt maar zodra ik de CSS link enzo aan toevoeg krijg ik deze error:

Warning: Cannot modify header information - headers already sent by (output started at /home/mzoomers/public_html/poll/admin.php:6) in /home/mzoomers/public_html/poll/admin.php on line 38

Ik weet dat het door de cookie komt, maar ik zou niet weten hoe ik die anders kan zetten. Iemand die mij kan helpen?

poll.php
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<? 

require("config.php");

echo "<link href=\"css\style.css\" rel=\"stylesheet\" type=\"text/css\">
<body class=\"maintable\">";

if($_GET[poll] == "stem") 
    { 
    $update = "UPDATE poll SET votes = votes + 1, $_POST[keuze] = $_POST[keuze] + 1 WHERE id = $_GET[id]"; 
    $query = mysql_query($update); 
     
    $cookie = $HTTP_COOKIE_VARS['poll'];   
    setcookie("poll", $cookie.'-'.$_GET[id], time()+3600*24*7*52);       
         
    header("location: poll.php?poll=uitslagen"); 
    } 

$select = "SELECT * FROM poll ORDER BY id DESC LIMIT 1"; 
$query = mysql_query($select); 

while ($row = mysql_fetch_object($query)) 
    { 
    echo "<form method=\"post\" action=\"poll.php?poll=stem&id=$row->id\">"; 
    echo "<b>$row->vraag</b><br>"; 
     
    $cookie = $HTTP_COOKIE_VARS['poll'];    
    $data = explode('-', $cookie);    
    $gestemd = "";    
           
    for ($i = 0; $i < count($data); $i++)    
        {    
        if($data[$i] == $row->id)    
            {    
            $gestemd = "ja";    
            }    
        }    
     
    if(($_GET[poll] == uitslagen) OR ("$gestemd" == "ja")) 
        {     
        @$procent = 100 / $row->votes; 
             
        for($i=1; $i <= $row->aantal; $i++) 
            { 
            $antwoord = "antwoord$i"; 
            $keuze = "keuze$i"; 
             
            $aantal = $row->$keuze; 
     
            @$breedte = $row->$keuze * $procent; 
            @$breedte = round($breedte,0);         
             
            echo $row->$antwoord." ($breedte%)<br>"; 
            echo "[img]\"poll.gif\"[/img]<br> \n"; 
            } 
        } 
    elseif($gestemd == "") 
        { 
        for($i=1; $i <= $row->aantal; $i++) 
            { 
            $antwoord = "antwoord$i"; 
             
            echo "<input type=\"radio\" name=\"keuze\" value=\"keuze$i\">".$row->$antwoord."<br> \n"; 
            } 
             
        echo "<input name=\"verzend\" type=\"submit\" value=\"Stem!\"><br>"; 
        echo "<a href=\"poll.php?poll=uitslagen\">uitslagen</a>"; 
        echo "</form>"; 
        } 
    } 
?>

</body>

admin.php
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<? 

require("config.php");

echo "<link href=\"css\style.css\" rel=\"stylesheet\" type=\"text/css\">
<body class=\"maintable\">";

if ($_GET[actie] == "") 
    { 
    echo "Poll admin<p>"; 
     
    echo "<a href=admin.php?actie=nieuw>Plaats een nieuwe poll.</a><br><hr>"; 

    $select = "SELECT * FROM poll ORDER BY id ASC"; 
    $res = mysql_query($select) or die(mysql_error()); 
     
    echo "<table>"; 
     
    while($row = mysql_fetch_object($res))             
        { 
        echo "<tr>"; 
        echo "<td width=250>$row->vraag<br></td>"; 
        echo "<td><a href=\"?actie=delete&id=$row->id\">Delete</a><br></td>"; 
        echo "<td><a href=\"?actie=edit&id=$row->id\">Verander</a><br></td>"; 
        echo "</tr>";         
        } 
         
    echo "</table>"; 
    }     
     
elseif ($_GET[actie] == "nieuw") 
    { 
    if ($_POST[submit]) 
        { 
        $query = "INSERT INTO poll (vraag, aantal, antwoord1, antwoord2, antwoord3, antwoord4, antwoord5) VALUES ('$_POST[vraag]', '$_POST[aantal]', '$_POST[antwoord1]', '$_POST[antwoord2]', '$_POST[antwoord3]', '$_POST[antwoord4]', '$_POST[antwoord5]')";  
        mysql_query($query) or die (mysql_error()); 
             
        header("location: admin.php");  
        } 
    else 
        { 
        echo "Nieuwe poll<p>"; 
         
        ?> 
        <form method="post" action="admin.php?actie=nieuw"> 
        Vraag <input name="vraag" type="text"><br> 
        Aantal keuzes <select name="aantal" id="aantal"> 
        <option value="2">2</option> 
        <option value="3">3</option> 
        <option value="4">4</option> 
        <option value="5">5</option> 
        </select><br> 
        Antwoord 1 <input name="antwoord1" type="text"><br> 
        Antwoord 2 <input name="antwoord2" type="text"><br> 
        Antwoord 3 <input name="antwoord3" type="text"><br> 
        Antwoord 4 <input name="antwoord4" type="text"><br> 
        Antwoord 5 <input name="antwoord5" type="text"><br> 
        <input name="submit" type="submit" id="submit" value="Maak"> 
        </form> 
        <?     
             
        } 
    } 
     
elseif ($_GET[actie] == "edit") 
    { 
    if ($_POST[submit]) 
        { 
        $query = "UPDATE poll SET vraagkort = '$_POST[vraagkort]', vraag = '$_POST[vraag]', aantal = '$_POST[aantal]', antwoord1 = '$_POST[antwoord1]', antwoord2 = '$_POST[antwoord2]', antwoord3 = '$_POST[antwoord3]', antwoord4 = '$_POST[antwoord4]', antwoord5 = '$_POST[antwoord5]' WHERE id = '$_GET[id]'";  
        mysql_query($query) or die (mysql_error()); 
             
        header("location: admin.php");  
        } 
    else 
        { 
        echo "Bewerk poll<p>"; 
         
        $select = "SELECT * FROM poll WHERE id = '$_GET[id]' ORDER BY id ASC"; 
        $res = mysql_query($select) or die(mysql_error()); 
         
        while($row = mysql_fetch_object($res))             
            { 
            ?> 
            <form method="post" action="admin.php?actie=edit&id=<?=$_GET[id] ?>"> 
            Vraag <input name="vraag" type="text" value="<?=$row->vraag ?>"><br> 
            Aantal keuzes (opnieuw kiezen) <select name="aantal" id="aantal"> 
            <option value="2">2</option> 
            <option value="3">3</option> 
            <option value="4">4</option> 
            <option value="5">5</option> 
            </select><br> 
            Antwoord 1 <input name="antwoord1" type="text" value="<?=$row->antwoord1 ?>"><br> 
            Antwoord 2 <input name="antwoord2" type="text" value="<?=$row->antwoord2 ?>"><br> 
            Antwoord 3 <input name="antwoord3" type="text" value="<?=$row->antwoord3 ?>"><br> 
            Antwoord 4 <input name="antwoord4" type="text" value="<?=$row->antwoord4 ?>"><br> 
            Antwoord 5 <input name="antwoord5" type="text" value="<?=$row->antwoord5 ?>"><br> 
            <input name="submit" type="submit" id="submit" value="Maak"> 
            </form> 
            <? 
            } 
        } 
    } 
     
elseif ($_GET[actie] == "delete") 
    { 
    $query = "DELETE FROM poll WHERE id = '$_GET[id]'";  
    mysql_query($query) or die (mysql_error()); 
             
    header("location: admin.php");  
    } 
?>

</body>

Acties:
  • 0 Henk 'm!

  • terrapin
  • Registratie: Februari 2002
  • Niet online
Je doet een echo voordat je je headers verstuurt, dat geeft die fout. Zet die echo met je stylesheet gewoon een stukje verder in je code..

The higher that the monkey can climb, The more he shows his tail


Acties:
  • 0 Henk 'm!

Verwijderd

zet
PHP:
1
2
echo "<link href=\"css\style.css\" rel=\"stylesheet\" type=\"text/css\"> 
<body class=\"maintable\">";

een stuk naar beneden zodat het onder de setcookie komt zodat de cookie nog in de header kan komen.

Acties:
  • 0 Henk 'm!

  • Ramon
  • Registratie: Juli 2000
  • Laatst online: 12:32
eerst je cookie en dán je HTML/CSS misschien? :)

Check mijn V&A ads: https://tweakers.net/aanbod/user/9258/


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
terrapin schreef op 08 May 2003 @ 14:30:
Je doet een echo voordat je je headers verstuurt, dat geeft die fout. Zet die echo met je stylesheet gewoon een stukje verder in je code..
Ok bedankt, maar hoever is verder of maakt dat weinig uit?
Ik neem aan dat hetzelfde geldt voor poll.php he ook al geeft ie aan dat de fout in admin.php zit?

Acties:
  • 0 Henk 'm!

  • terrapin
  • Registratie: Februari 2002
  • Niet online
altijd pas echo's gebruiken nadat je alle headerfuncties hebt gebruikt...

The higher that the monkey can climb, The more he shows his tail

Pagina: 1