Shocker88 Posted October 29, 2007 Share Posted October 29, 2007 Hey having some trouble setting a session from the result of this drop down box when submitted.. <?php //includes include('template1.php'); $query = "SELECT enemyname, enemyid FROM enemies ORDER BY enemyid asc"; $result = mysql_query($query); echo "<form method='post' action='attack.php'> <select name='enemies' value='enemies' id='enemies'>"; while($row = mysql_fetch_array($result)) { $r0 = $row[0]; $r1 = $row[1]; echo "<option value='$r1'>$r0</option>"; } echo "</select> <input type='submit' value='Attack' name='Attack'> </form><br>"; $_SESSION['enemies'] = $_POST['enemies']; include('template2.php'); ?> Everything seems to be working fine except for some reason the session is not setting to the value posted via the drop down. Quote Link to comment https://forums.phpfreaks.com/topic/75230-solved-setting-session-from-drop-down-submit/ Share on other sites More sharing options...
LemonInflux Posted October 29, 2007 Share Posted October 29, 2007 Isn't that because they're on the same page? You don't have a $_POST value until the form is submitted Quote Link to comment https://forums.phpfreaks.com/topic/75230-solved-setting-session-from-drop-down-submit/#findComment-380487 Share on other sites More sharing options...
trq Posted October 29, 2007 Share Posted October 29, 2007 Is this the attack.php script? You should be getting warning prior to posting the form because your using an array index ($_POST['enemies']) which is not yet set. Also, I see no call to session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/75230-solved-setting-session-from-drop-down-submit/#findComment-380489 Share on other sites More sharing options...
Shocker88 Posted October 29, 2007 Author Share Posted October 29, 2007 Thanks lol - this is why I should have stopped coding a while ago 3:30am is a bit late to be trying anything..time to head to bed Thanks heaps. Quote Link to comment https://forums.phpfreaks.com/topic/75230-solved-setting-session-from-drop-down-submit/#findComment-380490 Share on other sites More sharing options...
Shocker88 Posted October 29, 2007 Author Share Posted October 29, 2007 Nah - wasn't the attack.php script. session_start() is called in the template which is included at the top. Anyway thanks for the help should have posted earlier instead of beating my head against the wall because im too tired to think. Quote Link to comment https://forums.phpfreaks.com/topic/75230-solved-setting-session-from-drop-down-submit/#findComment-380492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.