Computing.Net > Forums > Web Development > PHP- Open Results on new Page?

PHP- Open Results on new Page?

Reply to Message Icon

Original Message
Name: meenxo
Date: March 26, 2004 at 19:22:24 Pacific
Subject: PHP- Open Results on new Page?
OS: NT
CPU/Ram: 384MB
Comment:

Hello,
I have downloaded a POLL script from scriptme.com and I have set it up on my website(http://tormusayya.com/poll2/vote.php)and its working fine!
One questions though! I want when I press "SHOW ME THE RESULTS" to open a new window! Please Help, below is my PHP script from my poll page.. Thank you


<?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=\"120\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
<tr><td bgcolor=\"$tableborder\">
<table width=\"120\" 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 "<form method=\"post\" action=\"$PHP_SELF\"><p align=\"center\">";
$data=file($datafile);
$question=$data[0];
$nb_options=count($data)-1;
if ($use_image==1) echo "$question

";
else if ($use_image==0)echo "$question
";

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]
</div>";
}
echo "<input type=\"hidden\" name=\"save\" value=\"yes\">";
echo "<p align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Submit\"></form>
";
echo "Show me the results</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;
if ($use_image==1) echo "<div align=\"center\">$data[0] ($votes v.)

";
else if ($use_image==0)echo "<p align=\"center\">$data[0] ($votes v.)</div>
";

do{
$subdata=explode("][",$data[$a]);
$av = $subdata[2] * $v;
echo "<div align=\"left\">$subdata[0] -"; printf(" %01.1f", $av); echo"%
";
$p2v = 100-$av;
echo "
";
$a++;
} while ($a < $nb_answers);
echo "
</div>";
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); }
?>



Report Offensive Message For Removal

Response Number 1
Name: anonproxy
Date: March 28, 2004 at 10:11:31 Pacific
Subject: PHP- Open Results on new Page?
Reply: (edit)

Your code refers to the the current page ($PHP SELF). So naturally, a new page is not going to display if you are only referring to the current page. In the form tag, add target="_blank".


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: PHP- Open Results on new Page?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software