Avatar billede mnt Nybegynder
09. oktober 2002 - 23:15 Der er 24 kommentarer og
1 løsning

Vote virker ikke...

Godaften..
Min vote på http://www.savnet.dk/_2718/web/vote/vote.php virker ikke.. Hvad er der ivejen?

Her er fra line 130 og ned:

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); }
Avatar billede ztyxx Nybegynder
09. oktober 2002 - 23:18 #1
du skal bruge de nye superglobals
Avatar billede alrua Nybegynder
10. oktober 2002 - 00:44 #2
$REMOTE_ADDR skal være $_SERVER['REMOTE_ADDR']
$action skal være $_POST['action']
$save skal være $_POST['save']
$PHP_SELF skal være $_SERVER['PHP_SELF']

Du skal nok også lave nogle isset() checks - men det lader jeg være op til dig : http://dk.php.net/manual/en/function.isset.php

-Alrua
Avatar billede mnt Nybegynder
10. oktober 2002 - 09:14 #3
Det virker altså ikke når jeg har ændre:
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); }

til:
$REMOTE_ADDR skal være $_SERVER['REMOTE_ADDR']
$action skal være $_POST['action']
$save skal være $_POST['save']
$PHP_SELF skal være $_SERVER['PHP_SELF']

Se selv >> http://www.savnet.dk/_2718/web/vote/vote.php

Her er hele min kode:
<?php
function head() {
include('config.php');
echo "<table width=\"200\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
<tr><td bgcolor=\"$tableborder\">
<table width=\"198\" 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\"><p align=\"center\">";
$data=file($datafile);
$question=$data[0];
$nb_options=count($data)-1;
echo "<b>$question</b></p>";
for($nb=1;$nb <= $nb_options; $nb++){
$option=explode("][","$data[$nb]");
echo "<input type=\"radio\" name=\"answer\" value=\"$nb\"> ";
echo "$option[0]<br>";
}
echo "<input type=\"hidden\" name=\"save\" value=\"yes\">";
echo "<p align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Stem\"></form></font>";
echo "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><a href=\""; echo $PHP_SELF; echo "?action=results\">Vis resultat</font></p>";
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;
echo "<p align=\"center\"><font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><b>$data[0] ($votes v.)</b><br><br>";
do{
$subdata=explode("][",$data[$a]);
$av = $subdata[2] * $v;
echo "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\">$subdata[0] -"; printf(" %01.1f", $av); echo"%<br>";
$p2v = 100-$av;
echo "<img src=\"$subdata[1]\" width=\"$av\" height=\"10\"><img src=\"$image\" width=\"$p2v\" height=\"10\"><br>";
$a++;
} while ($a < $nb_answers);
echo "<br>";
foot();
}
//###################### Engine ####################################
$REMOTE_ADDR skal være $_SERVER['REMOTE_ADDR']
$action skal være $_POST['action']
$save skal være $_POST['save']
$PHP_SELF skal være $_SERVER['PHP_SELF']
?>
Avatar billede alrua Nybegynder
10. oktober 2002 - 18:13 #4
det jeg skrev var en vejledning! ikke færdig kode!

Alle de steder hvor der står $REMOTE_ADDR skal du ændre til $_SERVER['REMOTE_ADDR'] og ligesådan med de andre:

$REMOTE_ADDR skal være $_SERVER['REMOTE_ADDR']
$action skal være $_POST['action']
$save skal være $_POST['save']
$PHP_SELF skal være $_SERVER['PHP_SELF']

Det er altså IKKE KODE! ;)

-Alrua
Avatar billede mnt Nybegynder
10. oktober 2002 - 18:27 #5
Jeg giver 10 mere point hvis du gider sætte det ind for mig?
Avatar billede alrua Nybegynder
10. oktober 2002 - 18:30 #6
ok så - giv mig lige 2 min :P
Avatar billede alrua Nybegynder
10. oktober 2002 - 18:37 #7
jeg har kun rettet det efter //## Engine ## - resten er vist som det skal være

Jeg kan ikke teste det, da jeg ikke har config.php

//###################### Engine ####################################
check($_SERVER['REMOTE_ADDR']);
if ($valid=="0"){ results();}
elseif ($_POST['action']=="results") { results(); }
elseif ($_POST['save']=="yes" && $valid!="0") { save($_POST['answer']); record($_SERVER['REMOTE_ADDR']); results();}
elseif ($_POST['action']=="save" && !empty($valid)) { results(); }
elseif ($_POST['action']!="save" && $valid!="0"){ form($PHP_SELF); }
?>
Avatar billede mnt Nybegynder
10. oktober 2002 - 19:16 #8
Okay, jeg prøver med ENGINE...
Avatar billede mnt Nybegynder
10. oktober 2002 - 19:18 #9
Der er stadig fejl??
Her er koden som er i vote.php lige nu:

<?php
function head() {
include('config.php');
echo "<table width=\"200\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
<tr><td bgcolor=\"$tableborder\">
<table width=\"198\" 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\"><p align=\"center\">";
$data=file($datafile);
$question=$data[0];
$nb_options=count($data)-1;
echo "<b>$question</b></p>";
for($nb=1;$nb <= $nb_options; $nb++){
$option=explode("][","$data[$nb]");
echo "<input type=\"radio\" name=\"answer\" value=\"$nb\"> ";
echo "$option[0]<br>";
}
echo "<input type=\"hidden\" name=\"save\" value=\"yes\">";
echo "<p align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Stem\"></form></font>";
echo "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><a href=\""; echo $PHP_SELF; echo "?action=results\">Vis resultat</font></p>";
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;
echo "<p align=\"center\"><font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><b>$data[0] ($votes v.)</b><br><br>";
do{
$subdata=explode("][",$data[$a]);
$av = $subdata[2] * $v;
echo "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\">$subdata[0] -"; printf(" %01.1f", $av); echo"%<br>";
$p2v = 100-$av;
echo "<img src=\"$subdata[1]\" width=\"$av\" height=\"10\"><img src=\"$image\" width=\"$p2v\" height=\"10\"><br>";
$a++;
} while ($a < $nb_answers);
echo "<br>";
foot();
}
//###################### Engine ####################################
check($_SERVER['REMOTE_ADDR']);
if ($valid=="0"){ results();}
elseif ($_POST['action']=="results") { results(); }
elseif ($_POST['save']=="yes" && $valid!="0") { save($_POST['answer']); record($_SERVER['REMOTE_ADDR']); results();}
elseif ($_POST['action']=="save" && !empty($valid)) { results(); }
elseif ($_POST['action']!="save" && $valid!="0"){ form($PHP_SELF); }
?>
Avatar billede alrua Nybegynder
10. oktober 2002 - 19:20 #10
hmm...kan du ikke poste din _oprindelige_ kode? den som var hele problemet? :D
Avatar billede mnt Nybegynder
10. oktober 2002 - 20:19 #11
Jo okay... Her er den:

<?php
function head() {
include('config.php');
echo "<table width=\"200\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
<tr><td bgcolor=\"$tableborder\">
<table width=\"198\" 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\"><p align=\"center\">";
$data=file($datafile);
$question=$data[0];
$nb_options=count($data)-1;
echo "<b>$question</b></p>";
for($nb=1;$nb <= $nb_options; $nb++){
$option=explode("][","$data[$nb]");
echo "<input type=\"radio\" name=\"answer\" value=\"$nb\"> ";
echo "$option[0]<br>";
}
echo "<input type=\"hidden\" name=\"save\" value=\"yes\">";
echo "<p align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Stem\"></form></font>";
echo "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><a href=\""; echo $PHP_SELF; echo "?action=results\">Vis resultat</font></p>";
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;
echo "<p align=\"center\"><font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><b>$data[0] ($votes v.)</b><br><br>";
do{
$subdata=explode("][",$data[$a]);
$av = $subdata[2] * $v;
echo "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\">$subdata[0] -"; printf(" %01.1f", $av); echo"%<br>";
$p2v = 100-$av;
echo "<img src=\"$subdata[1]\" width=\"$av\" height=\"10\"><img src=\"$image\" width=\"$p2v\" height=\"10\"><br>";
$a++;
} while ($a < $nb_answers);
echo "<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); }
?>
Avatar billede alrua Nybegynder
10. oktober 2002 - 20:22 #12
hmm...det ville hjælpe en del hvis du også gad poste config.php - så kan jeg nemlig teste :D
Avatar billede mnt Nybegynder
10. oktober 2002 - 20:34 #13
Her er den ;-):
<?php
$textcolor='#888888';
$linkcolor='#FFFFFF';
$bgcolor='#FFFFFF';
$tableborder='#FFFFFF';
$timeout='24';
$ip_file='ip.txt';
$font='Arial';
$fontsize='1';
$datafile='data.txt';
?>
Avatar billede alrua Nybegynder
10. oktober 2002 - 21:01 #14
kan godt kigge på den lige om 2 sek :)
Avatar billede mnt Nybegynder
10. oktober 2002 - 21:18 #15
Okay.. Tak
Avatar billede alrua Nybegynder
10. oktober 2002 - 21:22 #16
jeg tror nok at denne her virker - min giver fejl, men jeg tror det er fordi jeg mangler dine datafiler :D

<?php
function head() {
include('config.php');
echo "<table width=\"200\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
<tr><td bgcolor=\"$tableborder\">
<table width=\"198\" 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\"><p align=\"center\">";
$data=file($datafile);
$question=$data[0];
$nb_options=count($data)-1;
echo "<b>$question</b></p>";
for($nb=1;$nb <= $nb_options; $nb++){
$option=explode("][","$data[$nb]");
echo "<input type=\"radio\" name=\"answer\" value=\"$nb\"> ";
echo "$option[0]<br>";
}
echo "<input type=\"hidden\" name=\"save\" value=\"yes\">";
echo "<p align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Stem\"></form></font>";
echo "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><a href=\""; echo $PHP_SELF; echo "?action=results\">Vis resultat</font></p>";
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;
echo "<p align=\"center\"><font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><b>$data[0] ($votes v.)</b><br><br>";
do{
$subdata=explode("][",$data[$a]);
$av = $subdata[2] * $v;
echo "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\">$subdata[0] -"; printf(" %01.1f", $av); echo"%<br>";
$p2v = 100-$av;
echo "<img src=\"$subdata[1]\" width=\"$av\" height=\"10\"><img src=\"$image\" width=\"$p2v\" height=\"10\"><br>";
$a++;
} while ($a < $nb_answers);
echo "<br>";
foot();
}
//###################### Engine ####################################
check($_SERVER['REMOTE_ADDR']);
if ($valid=="0"){ results();}
elseif (isset($_POST['action']) && $_POST['action']=="results") { results(); }
elseif (isset($_POST['save']) && $_POST['save']=="yes" && $valid!="0") { save($_POST['answer']); record($_SERVER['REMOTE_ADDR']); results();}
elseif (isset($_POST['action']) && $_POST['action']=="save" && !empty($valid)) { results(); }
elseif (!isset($_POST['action']) && $valid!="0"){ form($_SERVER['PHP_SELF']); }
?>
Avatar billede mnt Nybegynder
10. oktober 2002 - 21:28 #17
Prøver
Avatar billede mnt Nybegynder
10. oktober 2002 - 21:29 #18
Nej den kommer med en ny fejl???
Avatar billede alrua Nybegynder
10. oktober 2002 - 21:34 #19
hmm...det er vist mig der har rodet lidt i det...

prøv at erstatte $_POST['action'] med $_GET['action'] alle steder hvor den forekommer :)
Avatar billede mnt Nybegynder
10. oktober 2002 - 21:43 #20
ok
Avatar billede mnt Nybegynder
10. oktober 2002 - 21:44 #21
Avatar billede alrua Nybegynder
10. oktober 2002 - 21:53 #22
hmm...det tror jeg desværre ikke at jeg kan hjælpe dig - jeg kan ikke lige gennemskue dit script. Du kan jo prøve at gå det hele igennem og find selv fejlen.

Beklager at jeg ikke kan hjælpe :(

Du behøver selvfølgelig ikke give mig nogle point...

-Alrua
Avatar billede mnt Nybegynder
10. oktober 2002 - 22:08 #23
Øv bøv....
En anden som kan`?????
Avatar billede alrua Nybegynder
10. oktober 2002 - 22:12 #24
slår lige email fra...
Avatar billede mnt Nybegynder
12. oktober 2002 - 18:13 #25
Okay jeg lukker..
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester