473,320 Members | 1,861 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,320 software developers and data experts.

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

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\00ideaselection.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 1531
computerfox
276 100+
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
thank you so much.....
Jun 13 '15 #3

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

Similar topics

8
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...
1
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...
1
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...
1
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...
1
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...
3
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...
1
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...
3
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...
0
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.