PHP Form Page Switcher

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paulcronin
Forum Newbie
Posts: 1
Joined: Mon Nov 08, 2010 7:04 am

PHP Form Page Switcher

Post by paulcronin »

Hi All,

I want to make a very simple 'search tool' that works by matching words from a form's input box to a specific page (i.e. if you enter 'Contact' the form would redirect you to contact.html).

index.html
<form method='post' action='forwarder.php'>
<input id="myInput" type="text">
<input type='submit'>
</form>

forwarder.phpThis doesn't work, but you get the idea...
<?php
switch($myInput) {
default:
include('no_match.html');
break; case "about":
include('about.html');
break; case "contact":
include('contact.html');
break; case "page1":
include('page1.html');
break; case "page2":
include('page2.html');
break; case "page3":
include('page3.html');
}
?>

Please can you help me with forwarder.php?

Thank you,
Paul
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Form Page Switcher

Post by AbraCadaver »

You are posting data from the form so the data is in the $_POST array:

Code: Select all

switch($_POST['myInput']) { 
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply