0

I know I this is simple, but i just can;t find the resource that tells me how to do it.

SO my code is as follows:

session_start();
$wquery=
"select week_num,week_name
from stats_week
where season=$this_season
order by week_num";
    $wresult=mysql_query($wquery);


print'<form action="changeplayer_2.php" method="post">';


        print"<select name='Week_select'> <br>";
        while ($wrow=mysql_fetch_array($wresult))
    { 
    print '<option value="'.$wrow['week_num'].'">'.'week '.$wrow['week_num'].'     '.$wrow['week_name'].'</option><br>\n';  
    }

print "</select><br><br>";#

    print'<button type="submit" >Next</button>';


    print"</form>";

So I am making a selection: I want that selection to end up in: $_SESSION['week']

Bill Flippen
  • 453
  • 1
  • 4
  • 19

3 Answers3

1
$_SESSION['week']=$_POST['Week_select'];
Cory Cox
  • 36
  • 2
  • maybe something like this `$_SESSION['week']=isset($_POST['Week_select'])?$_POST['Week_select']:some_default;` btw not sure op wants that – NullPoiиteя Apr 12 '13 at 04:41
  • it is not an answer.delete it and post it as a comment.otherwise ill vote you down – Freak Apr 12 '13 at 04:50
1

you can do this either sending data by form on submit or if you want to do without refreshing page you can do this by ajax

and than set like this

$_SESSION['week']=isset($_POST['Week_select'])?$_POST['Week_select']:someDefau‌​lt;

and to do this by ajax check this answer

Community
  • 1
  • 1
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
  • you have 21 and it require only 20 so i think you have .. just refresh page – NullPoiиteя Apr 12 '13 at 04:58
  • Thank you again for working it through with me. I ran into a stupid mistake, was uploading to the wrongdirectory so changes I made, weren't showing up. Anyway, the final answer in my own words here: when the item is selected it is POSTED in CHANGEPLAYER_2.PHP. All that is needed on page 1 is the SESSION_START(). on page 2, and other pages that also have SESSION_START(), all you have to do is $varWeek=$_POST['Week_select']. I was trying to do the assignment on page one. It was a misunderstanding of how SELECT and POST worked on my part. – Bill Flippen Apr 12 '13 at 13:55
0

Inside file "changeplayer_2.php" you'll want to load the POSTed value to the session:

session_start();
$_SESSION['week'] = $_POST['Week_select'];

Whenever you want to get the value of the session at key 'week', simply do:

$weekValue = isset($_SESSION['week']) ? $_SESSION['week'] : false;

But if you do use the session variable on any script, make sure you start the session using session_start().

To destroy the session variable, you can do:

session_start();
unset($_SESSION['week']);
Stegrex
  • 4,004
  • 1
  • 17
  • 19
  • not sure how to post code in a comment. here is my page 2 session_start(); $_SESSION['week'] = $_POST['Week_select']; $varWeek=$_SESSION['week'] echo 'Welcome to page #2
    '; echo 'week number :'.$varWeek; Still not getting it passed:(
    – Bill Flippen Apr 12 '13 at 04:56
  • Is the POST variable working? In your page 2, instead of `echo 'week number :'.$varWeek;` try `echo 'week number :'.$_POST['Week_select'];` to see if the POST is getting accepted by the page 2. – Stegrex Apr 12 '13 at 05:00
  • I was getting hung up on my troubleshooting because any changes ot the code wasn;t showing up on the page, I was uploading to the wrong directory. To elaborate a bit on your answer (which makes perfect sense now) when the item is selected it is POSTED in PAGE 1. With SESSION_START() you can then get the POST value and assign it to a variable as you stated on subsequent pages that have SESSION_START(). Thank you. – Bill Flippen Apr 12 '13 at 14:02