Forum Moderators: coopster

Message Too Old, No Replies

Trouble with redirection upon submission

         

sodani

10:06 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



Hi, I have a poll on my website, but I'm having trouble with the redirect when someone hits submit - it goes to the action php file, and not back to the home like I want them to. Here is my code if anyone can help me out.

<?php
include "connect.php";
$s=$_SERVER["REMOTE_ADDR"];
$ipcheck="SELECT * FROM P_ip where IP='$s'";
$ipcheck2=mysql_query($ipcheck);
while($ipcheck3=mysql_fetch_array($ipcheck2))
{
$ip=$ipcheck3[IP];
}
if($ip)
{
print "Thank you for voting in our poll";
}

else
{
$pollquest="SELECT*From P_question";
$p2=mysql_query($pollquest);
while($p3 = mysql_fetch_array($p2))
{
print "$p3[question] <br>";
}
$pollans="Select * from P_choices";
$pollans2=mysql_query($pollans);
print "<form action='wp-content/themes/matchbox1.1/pollit.php' method='post'>";
print "<input name='redirect' value='/' type='hidden'>";
while($pollans3=mysql_fetch_array($pollans2))
{
print "<input type='radio' name='answer' value='$pollans3[ID]'> $pollans3[answer]<br>";
}
print "<input type='submit' value='submit' value='vote'>";
print "</form><br>";

}
?>

nfs2

11:45 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



You need to show the code in pollit.php to see the problem.

Anyways, im thinking sedning a header like header("location: index.php"); after the script excecutes

sodani

11:59 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



Hi, here is the code for pollit.php

<?php
include "connect.php";
$s=$_SERVER["REMOTE_ADDR"];
$ipchecks="SELECT*from P_ip where IP='$s'";
$ipchecks2=mysql_query($ipchecks);
while($ipchecks3=mysql_fetch_array($ipchecks2))
{
$isip=$ipchecks3[IP];
}

if($isip)
{
print "Thank you for voting in our poll";
}

else
{
$ID=$_POST['answer'];
$ipinsert="Insert into P_ip(IP) VALUES('$s')";
mysql_query($ipinsert);
$vote = "UPDATE P_choices SET votes=votes+1
WHERE ID = '$ID'";
mysql_query($vote);
print "Thanks for voting, <a href='poll.php'>Back to Home</a>";
}
?>

nfs2

12:16 am on Mar 17, 2006 (gmt 0)

10+ Year Member



OK this is what i dont get. You say you want them re-directed right after they vote, but you are printing things and you have a "back to home" link there..

What is it you want to do? It seems when they hit submit, they are thanked for voting, and presented with a back to home link.. This isnt what you want?

The only spot i can see is

if($isip)
{
print "Thank you for voting in our poll";
}

Maybe add a home link there?

sodani

12:31 am on Mar 17, 2006 (gmt 0)

10+ Year Member



This is actually a poll script that I found. Right now, when you hit submit, it takes you to pollit.php, but what I really want is for people to hit submit and not be taken away from the original page. Does this make sense?

nfs2

12:46 pm on Mar 17, 2006 (gmt 0)

10+ Year Member



Yeah, like i said, instead of printing stuff on that page after the person votes, use a header like

header("location: index.php");

That'll send 'em back to the index (or whatever your main page is called)

Example:

if($isip)
{
header("location: index.php");
}

sodani

12:03 am on Mar 18, 2006 (gmt 0)

10+ Year Member



that works great. Thanks!