Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 7th, 2009, 11:34 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to instert a value list in the url

Hello all!

I would like some help on a project I`m working on.
What I want to do is to have a form with a list with 4 values (for example 11, 22, 33, 44) and a "Submit" button. I want that form to redirect to a web page (for example www.aabbcc.com). So when I choose value "22" I want to be redirected to the web page www.aabbcc.com/22. Which way should I do that?

Thank you in advance!
 
Old March 7th, 2009, 05:15 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default Use the header function to create a HTTP redirect header

Hi Varg,

This will do it for you.

PHP Code:
<?php

if(isset($_POST['num']))
{
  
header("location: http://www.aabbcc.com/" $_POST['num']);
  exit;
}

?>
<html>
<head>
</head>

<body>
<form action="redirectform.php" method="post">
<select name="num">
  <option value="11">Go to 11</option>
  <option value="22">Go to 22</option>
  <option value="33">Go to 33</option>
  <option value="44">Go to 44</option>
</select>

<input type="submit" value="GO!" />
</form>
</body>
</html>
On the page we create a select list called num with each number we want in the option values.
In the PHP which handles the submitted form, we check if a value for num was submitted, and if so add a HTTP header with the chosen number. So if we chose 22 the header would look like
location: http://www.aabbcc.com/22
This HTTP header is the way to put redirects in using php, so the browser will pick that up and redirect them to the fabulous aabbcc.com.
We also use exit; to stop the php script, as we don't need to process any other code or output the html.

You would probably want to add some things like checking if the value submitted is valid, but that's another topic.

Hope this helps
Phil
 
Old March 11th, 2009, 10:39 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is very helpful. I hope that I`ll be able to "transform" it in order to make it work in myspace.com. Thank you very much!
 
Old March 12th, 2009, 05:09 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I guess I`m not able to make that work on myspace.com. Could somebody transform this code in order to make it work please? Should I repost it in another category than PHP? I don`t know in whice "language" to search how to solve this problem.





Similar Threads
Thread Thread Starter Forum Replies Last Post
URL Redirect based on given URL somnath.kartic VS.NET 2002/2003 1 August 2nd, 2012 08:21 AM
URL rewriting with URL forwarding mtabyana BOOK: Professional Search Engine Optimization with PHP: A Dev's Guide to SEO ISBN: 978-0-470-10092-9 0 October 22nd, 2007 08:22 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
List tablesname from database & list databasename ittorget MySQL 3 September 10th, 2005 03:06 AM
extract URL from Favorites (.URL Files) PhilHawks VB.NET 2002/2003 Basics 2 November 2nd, 2004 04:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.