Question : Help with my PHP session Script

I've been working on the following for hours and it defies all my current understanding and logic of PHP. Please Help

In its most basic form I have a form that determines what is saved in a session: (http://www.alexjordan.co.uk/session.php)

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
<?php 
session_start(); 
$session = $_SESSION['delivery']; 
echo"<form action='http://www.alexjordan.co.uk/session_process.php' method='post'> 
    <select name='delivery' id='delivery'> 
      <option value='Please Select'>Please Select</option> 
      <option value='Standard UK'>Standard UK (FREE)</option> 
      <option value='Priority UK'>Priority UK (&pound;2.50)</option> 
      <option value='International'>International (&pound;10.00)</option> 
    </select> 
<input id='action' name='action' value='add_delivery_method' type='hidden' /> 
<input name='submit' value='submit' type='submit' /> 
</form>"; 
echo "Session: $session<br/><br/>"; 
echo "[<a href='http://www.alexjordan.co.uk/session_process.php?action=remove'>End Session</a>]"; 
?> 


When a value is chosen it is checked against a database and if it exists it will save the session, else it will not save the session.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
<?php 
session_start(); 
include("mysql.php");//Connects to DB 
$delivery = $_POST['delivery'];//Select Option from Session.php 
$redirect = "Location: http://www.alexjordan.co.uk/session.php"; 
// 
switch ($_REQUEST['action']) 
    { 
    case 'add_delivery_method': 
        $query = "SELECT * FROM griptape_delivery WHERE title='$delivery' AND active='1' "; 
        $result = mysql_query($query) or die(mysql_error()); 
        if (mysql_num_rows($result))//If delivery method is on DB 
            { 
            $_SESSION['delivery'] = "$delivery"; 
            header("$redirect?1"); 
            die(); 
            } 
        else//Else Ignore and keep current session 
            { 
            header("$redirect?2"); 
            die(); 
            } 
        break; 
         
    case 'remove'://End session 
        unset($_SESSION['delivery']); 
        header("$redirect?3"); 
        die(); 
        break; 
         
    default: 
        header("$redirect?4"); 
        die(); 
    } 
?> 


If you choose 'Please Select' when no session exists the script works well and no session is created because 'Please Select' is not in the Database.

If you choose one of the other 3 values it also works, creating a session, as these values are in the database. They also replace each other, as intended, when selected.

HOWEVER once a session exists and you choose 'Please Select' it saves the value 'Please Select' as a session despite not being in the database.

Have I missed something here? I've been on it for about 5 hours and I've rewritten the script in many ways with the same result.

Any help is greatly appreciated.

Answer : Help with my PHP session Script

Sorry, just to clarify the ?3 and the other numbers are not being used for anything other than to confirm which part of the script forwards to session.php when different values are inputted. If you go to http://www.alexjordan.co.uk/session.php you should see what I mean. It was meant to help so that you could see what happened when the different values were submitted.
Random Solutions  
 
programming4us programming4us