Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

having select option determine session variable 2

Status
Not open for further replies.

Chomauk

Programmer
Jun 8, 2001
130
I have a self processing form where I want the selected option to determine the session variable. Unfortunately I can't get it to work.

Everything appears to work but when I hit submit $_SESSION['GameWeek'] doesn't change. I'm sure it's got something to do with the input line.

HELP please?!

thanks
Code:
<?php
session_start(); 
header("Cache-control: private"); //IE 6 Fix
?>

<html>
<head>

<?php
echo "Session = ". $_SESSION['Week'];
echo "<form action=$PHP_SELF>" ;
?>

<select size=1 name="weeknum" width=20">

<script language="javascript">
i = 1
while (i <= 17)
{
document.write('<option name=' + i + '>' + i + '</option>');
i++
}
</script>
</select>

<input type="submit" value="Submit" onClick="<?php $_SESSION['Week'] ?> = list.options[list.selectedindex].value history.go()" >

</body>
</html>

If you're going through hell, keep going.
--Sir Winston Churchill (1874 - 1965) British Statesman, Prime Minister, Author
 
You're mixing Javascript and PHP. Remember PHP is server side and Javascript is client side.

A few potential problems in your script:
1) The <form> line probably should be
Code:
echo '<form action=' . $_SERVER['PHP_SELF'] .'>';

2) I'm not sure what you think
Code:
<input type="submit" value="Submit" onClick="<?php $_SESSION['Week'] ?> = list.options[list.selectedindex].value history.go()" >
is supposed to do. The PHP code in that string is meaningless, since it doesn't display anything.

I would suggest doing a "display source" in your browser to see the generated HTML code and start your debugging from there.

Ken
 
This is a simplified script that does what I think you're trying to do:

Code:
<?php
session_start(); 
header("Cache-control: private"); //IE 6 Fix

if (isset($_POST['weeknum']))
{
	$_SESSION['week'] = $_POST['weeknum'];
}


print '<html><body>';

if (isset($_SESSION['week']))
{
	print '$_SESSION[\'week\'] = "' . $_SESSION['week'] . '"';
}
else
{
	print '$_SESSION[\'week\'] is not assigned';
}

print '
<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
	<select size=1 name="weeknum" width=20">';
	
for ($counter = 1; $counter <= 17; $counter++)
{
	print '<option name="' . $counter . '">' . $counter . '</option>';
}

print '</select><input type="submit">
</body>
</html>';
?>


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks a bunch. I'm a happy camper again.

If you're going through hell, keep going.
--Sir Winston Churchill (1874 - 1965)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top