May 2nd, 2005, 01:49 AM
|
#1 (permalink)
| | Member
Join Date: Jan 2004
Posts: 242
|
Im trying to get a select form to pass some info to another page using php, but i can't seem to post the values correctly i guess. I have a regular submit form that is working well but this select one is confusing me a little. Code: $where=!isset($_POST['where_to_go'])? NULL: $_POST['where_to_go'];
<form action="redirect.php" method="post">
<select name="where_to_go" size=4>
<option value="search" SELECTED >Search</option>
<option value="add" >Add objects to database</option>
<option value="delete" >Remove objects from database</option>
<option value="edit" >Edit objects in database</option>
</select>
<input type="submit" value="Go">
</form> I used $_POST for the text submit form. I dont really know where to go from here.
edit: forgot about redirect.php: Code: <?
if($where=='search'){
header("Location: search.php");
}
else if($where=='add'){
header("Location: add.php");
}
else if($where=='delete'){
header("Location: delete.php");
}
else if($where=='edit'){
header("Location: edit.php");
}
else{
header("Location: auth.php");
}
?>
Last edited by engineuity : May 2nd, 2005 at 01:51 AM.
|
| |
May 2nd, 2005, 02:09 AM
|
#2 (permalink)
| | Perfetc Member
Join Date: Jan 2003 Location: Maryland Suburbia
Posts: 4,327
|
To access the variable Code: $where = $HTTP_POST_VARS['where_to_go']; Put that in your redirect.php file.
$_POST is another way to access variables, this does not "give" them to the other script in any way.
The form posts the variables for you when you have the form method "post"
Your first line doesnt really make any sense to me either.... Code: $where=!isset($_POST['where_to_go'])? NULL: $_POST['where_to_go']; If it is not set, you are setting the variable equal to null. Why are you doing that?
"$where" does not need come up at all except in your other script that is processing the form. Just remove that line...
Last edited by VHockey86 : May 2nd, 2005 at 02:12 AM.
|
| |
May 2nd, 2005, 02:10 AM
|
#3 (permalink)
| | Supporting our military
Join Date: Oct 2002 Location: Bottom left of U.S.
Posts: 9,194
|
Can't help you on it but HTML Forums has a section for php threads.
Bill
__________________
*****
It is easy to be conspicuously "compassionate" if others are being forced to pay the cost. – Murray N. Rothbard
|
| |
May 2nd, 2005, 03:03 PM
|
#4 (permalink)
| | Member
Join Date: Jan 2004
Posts: 242
|
for the $where=xxxx part, I was trying to follow a web example...didnt understand it either, but I figured i would need to $_POST to send to another page, thanks for clearing that up.
OK, most of it works now, except for when i use the search value. It refreshes the page, but removes my session. The other values like add, delete, they work fine and redirect to that page. I tried taking out the "SELECTED" part but that didnt change anything. |
| |
May 2nd, 2005, 03:21 PM
|
#5 (permalink)
| | Member
Join Date: Jan 2004
Posts: 242
|
nm...figured it out. I guess "search" is a reserved value, like submit. I changed value="search" to value="search_p" and now everything is fine. |
| |
May 2nd, 2005, 04:12 PM
|
#6 (permalink)
| | Ultimate Member
Join Date: Jan 2003 Location: MA / NH
Posts: 1,497
|
Well, first off, you are redirecting them twice, which is pointless. One redirect is all right, though you would be better off loading all from the same page in this case, IMO. Code: <?
//Retrieves which page they would like to view.
$page = $_POST["page"];
//If they did not select a page (I.E. initial visit to this page)
//Displays to them a form where they can pick where to go.
if($page == ""){
echo("
<form action='#' method='post'>
<select name='page' size=4>
<option selected value='1'>Search</option>
<option value='2'>Add objects to the database</option>
<option value='3'>Remove objects from database</option>
<option value='4'>Edit objects in database</option>
</select>
<input type='submit' value='Go'>
</form>
");
}
//If there is a page selected, then the proper page is loaded.
else{
switch ($page) {
case "1":
require ("search.php");
break;
case "2":
require ("add.php");
break;
case "3":
require ("delete.php");
break;
case "4":
require ("edit.php");
break;
default:
require ("auth.php");
}
}
?>
-Blaze |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | |
Similar Threads | | Thread | Thread Starter | Forum | Replies | Last Post | | PHP Form Help | Rand Dusing | Webmastering and Programming | 16 | September 4th, 2004 03:59 PM | | php mail form | data switch | Webmastering and Programming | 2 | July 6th, 2004 04:09 PM | | PHP form help | rh71 | Webmastering and Programming | 5 | January 24th, 2004 11:25 PM | | PHP Form | embj | Webmastering and Programming | 15 | February 19th, 2003 09:39 PM | | which way is proper PHP form | Chooco | Webmastering and Programming | 3 | March 22nd, 2002 02:08 AM | | Most Active Discussions | | | | | Recent Discussions  | | | | | |