Hello. I am currently working on a website to post some articles I write for my friends. The problem I am currently having is with a dynamic redirect. I have a dropdown list that is populated dynamically from a mysql database. That part is working fine but I can't get the redirect to include the id number of the selected item in the dropdown list. I want to redirect the user to another file on the same site where the ?id= the id of the selected month. If I change both instances of post in the below code to get and click go it shows the correct id number in the address bar but does not redirect. Keeping the below code as is causes it to redirect but the id number is blank so no page shows up. Any help you can provide would be appreciated.

echo '</td><form action="httest.php" method="post"><td>
<SELECT NAME=months> 
<OPTION VALUE=0>Choose Month</option>='.$months.' 
</SELECT><input type="submit" name="month" value="Go"></td></form>';

if (isset($_POST['month'])){
$pid = $_post['months'];
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: arttest.php?id=$pid"); 
exit(); 
}

when using header, it should be on the top. always. instead, try this one

if (isset($_POST['month'])){
$pid = $_post['months'];
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: arttest.php?id=$pid"); 
exit(); 
}
echo '</td><form action="httest.php" method="post"><td>
<SELECT NAME=months> 
<OPTION VALUE=0>Choose Month</option>='.$months.' 
</SELECT><input type="submit" name="month" value="Go"></td></form>';

if still doesn't work you should try using HTMLs Redirect

<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"></HEAD>

or maybe use javascript? http://www.tizag.com/javascriptT/javascriptredirect.php


Goodluck :D

Thanks. I switched like you said but it still wasn't working. I forgot about the case in POST. Once I capitalized it the button was working properly.

For Dynamic Redict Use this....It may help you a lot.

function redirecturl($url)
{
echo '<script type="text/javascript">';
echo "window.location='$url';";
echo '</script>';
}

Thanks,
Karthik,

Good! :) Glad you figure it out :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.