473,549 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to save an option in a dropdown menu as a php session variable?

14 New Member
I am trying to save one of the options in a dropdown menu as a session variable.
Expand|Select|Wrap|Line Numbers
  1. <select name="number" id="number">
  2.             <option>one</option>
  3.             <option>two</option>
  4.             <option>three</option>
  5.         </select>
  6.  
  7.             <?php
  8.          session_start();
  9. $_SESSION['number'] = $_POST['number'];
  10. ?>
  11.  
What it returns in the browser page is:

Notice: Undefined index: number in C:\xampp-portable\htdocs \eva\00ideasele ction.php on line 46
What is the error here?
What is the best way to save an option from a dropdown menu as session variable?
Jun 12 '15 #1
2 1561
computerfox
276 Contributor
I would suggest building a method in the header of the page that takes in a parameter of the value you want to set, then set the cookie or session. That is to say:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     ....
  4.     ....
  5.     <?php 
  6.      function set_session($value){
  7.       setcookie("Option",$value);
  8.      }
  9.     ?>
  10.   </head>
  11.   <body>
  12.     /// put form data here
  13.  
  14.    <?php
  15.      if(islet($_POST['submit'])){
  16.       set_session($_POST['number']);
  17.      }
  18.     ?>
  19.    </body>
  20. </html>
  21.  
I am also posting a link to a great resource I recommend you look over:
http://www.php-fig.org/psr/psr-1/

Hope that helps!
Jun 13 '15 #2
rose merry
14 New Member
thank you so much.....
Jun 13 '15 #3

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

Similar topics

8
7039
by: Tammy B. | last post by:
Hiya - Big puzzler for me. Code Below I create a class. I save it to a session variable. Then, I retrieve the session variable back into a new local variable. I am able to use a method which prints the name "Joey." Works great. But if I retrieve the same session variable into a local variable from a different page, I cannot use the...
1
2850
by: Dennis M. Marks | last post by:
Is there a javascript alternative to the dropdown menu in a form (SELECT OPTION). I would like the ability to pass a selected item to a function but I would like more control in the design of the menu. I would like to have different colors within a single line of the menu and different colors on selected lines. It would also be nice to have...
1
1750
by: Mosher | last post by:
Hi all, I am looking for some event handler auto-calc help on a form that takes user input through text fields and dropdown menus. I would like some of the text fields to be auto populated when dropdown menu selections are made. Here is an abstract html/javascript form: <form> Enter how much money you are willing to spend:<input type=text...
1
1727
by: SLH | last post by:
i have an asp page with a form that posts to itself. (the action of the form is the same page the form is on). i validate input and dont accept it if there is something wrong with it. problem is that when the form is submitted, and i display the error message, the data the user typed in the box is gone. i work around this by setting a session...
1
1525
by: payalbansal | last post by:
please help i just want to know is it possible to save the form at runtime in visual basic. Actually form is retrieving data from an excel file and now i just want to save the form. Is this really possible, if so how i can really do it
3
3471
by: Ninio | last post by:
I have a simple form with a dropdown menu that consists of 3 option and each option should retrieve a query from a database. i have been looking all over the place and can't seem to find how to do that. If anyone out there can help me i will be very grateful. this is the form: <form id="form1" name="form1" method="post" action=""> ...
1
2847
SHOverine
by: SHOverine | last post by:
Recently my web host decided to "upgrade". This change rendered many of my pages useless and I am scrambling to fix the issues, so you may see several posts from me in the coming days. My first issue is that all of my dropdown menus are passing the last row to the next page as the session variable. The pages that I am talking about can be...
3
2534
by: reigns7703 | last post by:
Hi all! I am a newbie and unfamiliar with PHP and MySQL... I am trying to create a dropdown menu that defaults to all items in my database while still allowing one to also filter to certain products. Right now, I have a database named Products and am trying to base my dropdown off of the three different Product_Type items (Chips, Dips &...
0
1216
by: getmeuser | last post by:
Hello Friends Actually I want to save the content of entry using Save Option in menu.I can directly use the e.get() but problem is I am creating entry and label depending upon total count in a file(comp_lis.txt). And that is created easily but what I need is to save the content of each entry box through menubar,so when I clicked on Save in...
0
7450
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6043
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.