[PHP] Notice: Undefined variable

Pagina: 1
Acties:
  • 68 views sinds 30-01-2008

  • X-GeaR
  • Registratie: September 2003
  • Laatst online: 12:46
Hallo!

Ik heb sinds een lange tijd een poll systeem. Nu heb ik op dezelfde pagina ook een 'laatste 10 forum berichten geinclude. Nu geeft het poll systeem een foutmelding.

FORUM SCRIPT

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
<?php 
error_reporting(E_ALL); 
include("http://www.astrostart.nl/phpBB2/config.php"); 

$limit = 10; //aantal topics
$letters = 28; //aantal letters voor strip
$forumpath = "http://www.astrostart.nl/phpBB2/"; 


function strippen($c,$letters){ 
    if(strlen($c) > $letters){ 
        $kort = substr($c, 0, $letters); 
        $laatste_spatie = strrpos($kort, ' '); 
        $kort = substr($kort, 0, $laatste_spatie); 
        $c = $kort.'...'; 
        return $c; 
    } 
    else{ 
        return $c; 
    } 
} 

$hostname = "127.0.0.1"; 
$user = "trostart"; 
$password = "klompen"; 
$database = "astrostart_nl_-_db"; 

mysql_connect($hostname, $user, $password) or die ("Kan geen verbinding maken met de host"); 
mysql_select_db($database) or die ("Kan de database niet openen"); 

$query = "SELECT topic_id,topic_title FROM phpbb_topics WHERE topic_status != 1 ORDER BY topic_last_post_id DESC LIMIT 0,".$limit; 

$res = mysql_query($query) or die(mysql_error()); 

while($data = mysql_fetch_assoc($res)){ 

   $topic_titel = strippen(stripslashes($data["topic_title"]), $letters); 
          
    echo "<font face=Verdana size=1 color=000000>- <a href=\"".$forumpath."viewtopic.php?t=".$data["topic_id"]."\" title=\"Forum topic :: ".$data["topic_title"]."\" onmouseover=\"window.status='Forum topic :: ".addslashes($data["topic_title"])."';return true\" target=\"_blank\">".$topic_titel."</a></font><br>"; 

} 
?>


Hieronder het POLL SCRIPT.

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
114
115
116
117
118
119
<?php
#####################################
# SMe Poll                          #
# written by scriptme               #
# http://www.scriptme.com           #
#####################################
    if (!ini_get ("register_globals"))
    {//globals turned Off
    extract($HTTP_GET_VARS);
    extract($HTTP_POST_VARS);
    extract($HTTP_COOKIE_VARS);
    extract($HTTP_ENV_VARS);
    extract($HTTP_SERVER_VARS);
    }
function head() {
include('config.php');
echo "<table width=\"196\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr><td bgcolor=\"$tableborder\">
<table width=\"196\" border=\"0\" cellpadding=\"0\" cellspacing=\"\" align=\"center\">
<tr><td bgcolor=\"$bgcolor\">";
}
function foot () {
echo "</td></tr></table></td></tr></table>";
}
function record($REMOTE_ADDR) {
include('config.php');
$fp=fopen("$ip_file", "a+");
fputs ($fp,$REMOTE_ADDR."][".time()."\n");
fclose($fp);
}
function check($REMOTE_ADDR) {
include('config.php');
global $valid;
$ip=$REMOTE_ADDR;
$data=file("$ip_file");
$now=time();
foreach ($data as $record) {
$subdata=explode("][",$record);
if ($now < ($subdata[1]+3600*$timeout)) {
if ($ip == $subdata[0]) {
$valid=0;
break;
}}}}
//##################### Save data ##############################

function save($answer){
global $answer;
include('config.php');
$data=file($datafile);
$subdata=explode("][",$data[$answer]);
$subdata[2]+=1;
$data[$answer]=implode("][", $subdata);
$data[$answer]=$data[$answer]."\n";
$fp=fopen($datafile,"w+");
$a=0;
do{
fputs($fp,$data[$a]);
$a++;
}while($a<count($data));
fclose($fp);
}
//########################## Show Form ############################
function form($PHP_SELF){
include('config.php');
head();
echo "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><form method=\"post\" action=\"$PHP_SELF\"><div align=\"center\">";
$data=file($datafile);
$question=$data[0];
$nb_options=count($data)-1;
if ($use_image==1) echo "<b>$question</b><br><br>[img]\"$image_for_vote\"><b></b><br><br>";
else[/img]$question</b><br>";

for($nb=1;$nb <= $nb_options; $nb++){
$option=explode("][","$data[$nb]");
echo "<div align=\"left\"><input type=\"radio\" name=\"answer\" value=\"$nb\"> ";
echo "$option[0]<br></div>";
}
echo "<input type=\"hidden\" name=\"save\" value=\"yes\">";
echo "<p align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Stem\"></form></font></div>";
foot();
}
//################## Function to show results ########################
function results(){
include('config.php');
head();
$data=file($datafile);
$nb_answers=count($data);
$votes=0;
$a=1;
do{
$subdata=explode("][",$data[$a]);
$votes += $subdata[2];
$a++;
}while($a < $nb_answers);
$a=1;
$b="answerv";
$v=100/$votes;
if ($use_image==1) echo "<br><br><div align=\"center\"><b>$data[0]</b><br><br>($votes keer gestemd)<br>[img]\"$image_for_vote\"><b></b><br>";
else[/img]<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><b>$data[0]</b><br>($votes keer gestemd)</div><br>";

do{
$subdata=explode("][",$data[$a]);
$av = $subdata[2] * $v;
echo "<div align=\"left\"><font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\">$subdata[0] -"; printf(" %01.1f", $av); echo"%<br>";
$p2v = 100-$av;
echo "[img]\"pollknop3.jpg\"[/img][img]\"$subdata[1]\"[/img][img]\"pollknop2.jpg\"[/img][img]\"pollknop.jpg\"[/img]<br><br>";
$a++;
} while ($a < $nb_answers);
echo "</div></br>";
foot();
}
//###################### Engine ####################################
check($REMOTE_ADDR);
if ($valid=="0"){ results();}
elseif ($action=="results") { results(); }
elseif ($save=="yes" && $valid!="0") { save($Answer); record($REMOTE_ADDR); results();}
elseif ($action=="save" && !empty($valid)) { results(); }
elseif ($action!="save" && $valid!="0"){ form($PHP_SELF); }
?>


Waar zit hem precies de fout?

Foutmelding is:

Notice: Undefined variable: action in /var/www/html/vote.php on line 115

Notice: Undefined variable: save in /var/www/html/vote.php on line 116

Notice: Undefined variable: action in /var/www/html/vote.php on line 117

Notice: Undefined variable: action in /var/www/html/vote.php on line 118

Hieronder de vier regels:

PHP:
1
2
3
4
elseif ($action=="results") { results(); }
elseif ($save=="yes" && $valid!="0") { save($Answer); record($REMOTE_ADDR); results();}
elseif ($action=="save" && !empty($valid)) { results(); }
elseif ($action!="save" && $valid!="0"){ form($PHP_SELF); }


Tenslotte nog even de include code. (test.php is het bestandje met de laatste forumberichten).

PHP:
1
2
3
4
5
6
7
8
9
10
<?php
include "test.php";

?>
            [img]"links4.jpg"[/img]<br>
            [img]"blokj.jpg"[/img]<br>
<?php
include "vote.php";

?>


Kan iemand helpen met het fixen van dit probleem?

  • sjroorda
  • Registratie: December 2001
  • Laatst online: 14:37
Dit is geen fout, dit is een waarschuwing, en betekent dat de betreffende variabelen wellicht nog niet geïnitialiseerd zijn, voordat je ze gebruikt.

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 20-11 11:59

NMe

Quia Ego Sic Dico.

We geven in Programming & Webscripting geen support op gedownloade code, en bovendien is debuggen iets wat je zelf moet kunnen. Deze gaat dus dicht. Met de tip van sjroorda moet je eruit kunnen komen. :)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Dit topic is gesloten.