473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

drop-down menu and conditional response on page 2

djsjm
23
Hi there... total newbie here... just typed out a beautiful question and then it sent me to log in and my question has just joined the stash of lost socks from washing machines. Start over.

I'm trying to learn php to make 3 pages of my site functional. I have lots of questions... but I'll narrow it down to just one for this post. Let me also say that I'm a do-it-yourselfer and like to find the answers myself... and if there was a tracker on google search, you'd see I've been busy ramming my head against a wall for almost two weeks now.

I have a pull down menu with three choices, as part of a form on page 1.

I would like the text displayed on page 2 to reflect what the user's choice was on page 1.

Will someone point me in the right direction? What do I need to study... sessions... includes... if, ifelse.......

I'm learning a lot, but not what I need for this particular task.

Thanks in advance.
Nov 1 '08 #1
6 1640
Atli
5,058 Expert 4TB
Hi.

I think you may find this article helpful. It's about how to use HTML forms to pass your data to PHP.

The short version of that would be:

If you have a HTML <form>, somewhat like this:
Expand|Select|Wrap|Line Numbers
  1. <form action="process.php" method="post">
  2.   <input type="text" name="someValue" /><br />
  3.   <input type="submit" />
  4. </form>
  5.  
Once submitted, this code in the "process.php" file would show you what the user typed in the "someValue" textbox:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   echo $_POST['someValue'];
  3. ?>
  4.  
All the values the user chose for all <input>, <textarea> and <select> elements inside the <form> element are passed to the $_POST super-global as an array, using the "name" attribute of the element as the key.
Nov 1 '08 #2
djsjm
23
Hi Atli,

Thanks for your quick response. I had already read the article that you linked to, as well as about 100 other tutorials online saying the same thing. What I need is to go beyond merely displaying what the choice was.

I'd like the page content to be different based on that choice. If there was a way to put an if (or something) into the action element of the form, then I could just direct the user to a specific page based on their choice... rather than trying to change the content of one page.

Does that make sense? I know I don't have the lingo and everything right... I didn't even know php existed until a couple of weeks ago.

Thanks again.
Nov 1 '08 #3
Atli
5,058 Expert 4TB
Ok I see.

You could use the header function to re-direct the client to another page based on the value that was passed to your script.

A simple if statement would be all that you needed. (Although there are a lot of alternatives to that.)

Something as simple as this might work:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if($_POST['pageSelection'] == "home") {
  3.   header("Location: index.php");
  4. }
  5. else if($_POST['pageSelection'] == "login") {
  6.   header("Location: memberLogin.php");
  7. }
  8. else {
  9.   header("Location: pageSelectionForm.html");
  10. }
  11. ?>
  12.  
This would simply check the value of a "pageSelection" variable, sent via a <form>. It would redirect to specific pages if it was past "home" or "login", or simple go back to the form if anything else is sent. (The page with the form being "pageSelectionForm.html")

Some people might recommend the switch statement rather than the if statements, but I have personally never seen the point of it.
Nov 2 '08 #4
Markus
6,050 Expert 4TB
In C#.NET switch() is generally considered to be faster but less flexible than if(). I'm not sure if the speed difference is true with PHP, though.
Nov 2 '08 #5
Atli
5,058 Expert 4TB
In C#.NET switch() is generally considered to be faster but less flexible than if(). I'm not sure if the speed difference is true with PHP, though.
That doesn't seem to be the case with PHP.
I've just done a few simple tests and if() appears to be like 3% faster than switch().
Nov 2 '08 #6
djsjm
23
Thanks for the advice! I did end up getting it to work the other night using "include". Just getting back to work now after having the flu. At least I was the one with the virus and not my pc. =)

Now for a new post with a new question...
Nov 3 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: riehe | last post by:
Dear all I want to drop a node from a nodegroup. Can someone confirm if its enough to redistribute a node group with a partition map which doesn't include the node to be dropped? I can't see...
1
by: Ian Dobson | last post by:
Hi, I need to drop a schema from a database but it has 400 tables in it. Is there an easy way to do it other than drop table schema1.table1 drop table schema1.table2 etc.. to 400 and then drop...
10
by: BuddhaBuddy | last post by:
Platform is DB2/NT 7.2.9 The table was created like this: CREATE TABLE MYTEST ( MYTESTOID bigint not null primary key, FK_OTHEROID bigint not null references other, FK_ANOTHEROID bigint not...
0
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot...
8
by: WindAndWaves | last post by:
Hi everyone, Has anyone got any experience with drop and drag in Access? I would like to make a calendar style form where my users can drop and drag appointments.... I am using Access 2003...
1
by: Torre Quinn | last post by:
Does anyone have any good sites or resources dealing with adding drag and drop functionality to a set of controls on a form? I'd like to try to get several examples of varied applications of drag...
3
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
1
by: Darren | last post by:
I'm trying to create a file using drag and drop. I want to be able to select a listview item drag it to the shell and create a file. Each icon in the listview represents a blob in a database. When...
15
by: uwcssa | last post by:
I try to drop a table as: I got: During SQL processing it returned: SQL0478N The object type "TABLE" cannot be dropped because there is an object "sch.SQL070515104729271", of type "FUNCTION",...
1
by: Thi | last post by:
Hi, I am trying to develop an application that allows the users to drag a few file(s) from a zip archive to a destination. My question is, how do i determine where the drop destination is...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.