Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 23
  1. #1

    Undefined variable: PHP_SELF

    Rieccomi,
    Ho questo script preso da freephp.it per rispondere ad un sondaggio.
    Quello per inserire il sondaggio l'ho risolto grazie all'aiuto di Daniele.
    Adesso non volevo rompere ulteriormente ma dopo svariati tentativi e letture di vari post sull'argomento sono riuscito ad evitere alcuni Notice ma alla fine mi da il seguente errore:

    Notice: Undefined variable: PHP_SELF in C:\siti\prova\sonda\vote.php on line 71
    questa è la linea 71
    Codice PHP:
      echo "<font face=\"Verdana\" size=\"1\"><a href=\"".$PHP_SELF."?results=1\" target=\"_blank\">View results</a></font>"
    Questo è l'intero script
    Codice PHP:
    <?
     
    require_once("settings.inc");
     
    $poll mysql_connect("$db_host""$db_username""$db_password")
            or die (
    "Could not connect");
     
    mysql_select_db ("cerebus")
            or die (
    "Could not select database");
            
         
    $checkforcurrent mysql_query("select id,dateactive from polls where active='yes' order by question limit 1");
         
    $current_poll mysql_fetch_row($checkforcurrent);
         
    $curpollid $current_poll[0];
         
    $dateactive $current_poll[1];
         
    $today=date("Y-m-d 00:00");
         
    $date1=strtotime"$dateactive 00:00" );
         
    $date2=strtotime("$today");
         
    $datediffer = (($date2-$date1)/86400);
         
     if (
    $datediffer>=$interval){
         
    $lookfornext mysql_query("select id from polls where active='no' order by id limit 1");
         
    $getnextid mysql_fetch_row($lookfornext);
         
    $nextpollid $getnextid[0];
         if (
    $nextpollid){
              
    $date date("Y-m-d");
              
    mysql_query("update polls set active='end' where id=$curpollid");
              
    mysql_query("update polls set active='yes', dateactive='$date' where id=$nextpollid");
              
    mysql_query("delete from poll_ip");
         }
     }

     function 
    writeresults (){
         
    $getquestion mysql_query("select id,question,votes from polls where active='yes' order by question limit 1");
         
    $question mysql_fetch_row($getquestion);
         echo 
    "<font face=\"Verdana\" size=\"2\">[b]".$question[1]."[/b]

    "
    ;
         
    $totalvotes $question[2];
         
    $getresults mysql_query("select votes, alternative from poll_alternatives where poll_id='$question[0]'");
         
    $imageid=1;
         while (
    $result mysql_fetch_array($getresults)){
            if (
    $totalvotes!=0){
            
    $percentage = (round(($result["votes"]/$totalvotes)*10000))/100;
        }
            
    $imagewidth round($percentage*2);
            echo 
    $result["alternative"]." - $percentage% (".$result["votes"]." votes).
    "
    ;
            echo 
    "<img src=\"$imageid.gif\" width=\"$imagewidth\" height=\"10\" style=\"border:1px solid black\">

    "
    ;
            
    $imageid++;
         }
         echo 
    "
    A total of 
    $totalvotes votes has been submitted on this question.</font>";
    }


    if(!isset(
    $submit) & !isset($results)) {
         
    ?>
         <form method="post" action="<? echo $_SERVER['PHP_SELF'?>" target="_blank">
         <font face="Verdana" size="2">
         <?

         $getquestion 
    mysql_query("select id,question from polls where active='yes' order by question limit 1");
         
    $question mysql_fetch_row($getquestion);
         
    $pollid $question[0];
         
    $dateactive $question[1];
         
    $question $question[1];
         echo 
    "[b]$question[/b]

    "
    ;
         
    $getalternatives mysql_query("select id, alternative from poll_alternatives where poll_id='$pollid'");
         while (
    $writeit mysql_fetch_array($getalternatives)){
               echo 
    "<input type=\"radio\" name=polloption value=\"".$writeit["id"]."\"";
               if (!isset(
    $checkedvar)){ echo "checked"$checkedvar=1; }
               echo 
    ">";
               echo 
    " ".$writeit["alternative"]."
    "
    ;
         }
         echo 
    "<input type=\"hidden\" name=\"pollid\" value=\"$pollid\"></font>";
         echo 
    "
    <center><input type=\"Submit\" value=\"Vote\" name=\"submit\""
    ;
         echo 
    " style=\"background-color:white; color:black; font-family:Verdana; font-size:12px\">
    "
    ;
       echo 
    "<font face=\"Verdana\" size=\"1\"><a href=\"".$PHP_SELF."?results=1\" target=\"_blank\">View results</a></font>";
         echo 
    "</center></form>";
     }
      
     elseif (isset(
    $submit)){
         
    $checkforip mysql_query("select ip from poll_ip where ip='$REMOTE_ADDR'");
         if (
    mysql_num_rows($checkforip)==0){
         
    mysql_query ("update poll_alternatives set votes=votes+1 where id='$polloption'");
         
    mysql_query ("update polls set votes=votes+1 where id='$pollid'");
         
    mysql_query ("insert into poll_ip (ip) values ('$REMOTE_ADDR')");
         echo 
    "<font face=\"Verdana\" size=\"2\">Your vote has been counted.

    </font>"
    ;
         }
         else { echo 
    "<font face=\"Verdana\" size=\"2\">Only one vote per ip allowed.

    </font>"
    ;}
         
    // skriva ut resultat
         
    writeresults();
      }

      elseif(
    $results){
          
    writeresults();
      }  
         
     
    mysql_close($poll);
    ?>

  2. #2
    prova a usare $_SERVER['PHP_SELF'] al posto di $PHP_SELF


  3. #3
    Ciao
    ho provato, adesso non da più l'errore ma non salva nessun dato nel DB.

  4. #4
    prova a mettere
    codice:
    or die (mysql_error());
    a tutti i mysql_query, così vedi l'errore che ti da

  5. #5
    Fatto.
    Nessun errore

  6. #6
    ma scusa prima te li salvava nel database i dati?

  7. #7
    Si.
    In effetti se imposto register_globals a ON mi salva i dati nel DB.

    Ti spiego brevemente come dovrebbe funzionare.

    Dopo aver effettuato la scelta facendo il submit mi stampa la pagina con il risultato del sondaggio (voti, percentuali, e grafico) però questo funziona solo con register_globals a ON.
    Con register_globals a OFF mi fa apparire la stessa pagina.

  8. #8
    ciao...è ESATTAMENTE lo stesso problema di prima

  9. #9
    Ciao Daniele,
    avevo capito che era lo stesso problema di prima ma pur avendo fatto e rifatto sono riuscito a risolvere alcuni errori ma questo niente.
    L'unica cosa che sono riuscito a capire è che sono proprio di coccio.

    ciao

  10. #10

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.