tags:

views:

75

answers:

1

Ok this is a very small section of my original code. I have two pages a page full of forms and boxes then another page that puts the information into my DB.

Oasis.php page This right here is the code that changes the client name and code. On this entire page. On the change event.

$sql = "SELECT * FROM client_lookup ORDER BY Client_Full_Name ASC"; 
$result = mysql_db_query ($dbName, $sql, $dbLink); 

$options4=""; 

while ($row = mysql_fetch_array($result)) { 

    $id=$row["Client_Code"]; 
    $thing=$row["Client_Full_Name"]; 
    $options4.="<OPTION VALUE=\"$id, $thing\">".$thing; 
} 
?>
<FORM name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<SELECT NAME="ClientNamefour" OnChange="this.form.submit()">
    <OPTION VALUE=0>Client
    <?php echo $options4?> 

  </SELECT>
</FORM>

Once the form below this on the Oasis.php page is submitted it goes to the process page and puts the information into my data base. Once that is done I have a header that returns me to this page. But as default the Client is always returned.

In an attempt to return the previously selected client from this drop down I used this code. To automatically select the last selected client.

$sql = "SELECT * FROM client_lookup ORDER BY Client_Full_Name ASC"; 
$result = mysql_db_query ($dbName, $sql, $dbLink); 


session_start();

$current = isset($_SESSION['ClientNamefour']) ? $_SESSION['ClientNamefour'] : 0;

$options4=""; 

while ($row = mysql_fetch_array($result)) { 


    $id = $row["Client_Code"]; 
    $value = $row["Client_Full_Name"];
        $key = "$id, $value";


    $selected = ($id == @$_SESSION['ClientNamefour']) ? ' selected' : '';
    $options4.="<option value=\"{$key}\"{$selected}>{$value}";
} 


?>

<FORM name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

<SELECT NAME="ClientNamefour" OnChange="this.form.submit()">

    <OPTION VALUE=0>Client
    <?php echo $options4?> 

  </SELECT>
</FORM>

This works but the onchange event doesn't not work! So it doesn't Post itself. The on change event is key or my whole page doesn't populate with information.

A: 

You read $_SESSION['ClientNamefour'] but never write to it... I think you're confusing $_SESSION with $_POST. If you used $_POST instead, $_POST['ClientNamefour'] would be the value of the <select> as the <select> has a name attribute of 'ClientNamefour'.

On a side note, you never manipulate variable $current and - maybe this is PHP syntax I'm unfamiliar with - when you manipulate $_SESSION['ClientNamefour'] there's a commercial at character @ just before the $...

LeguRi
What really needs to happen here is.. A session takes my data from the drop down listed above. Its gonna take it to the process page then bring it back to this page with a header on the process page. Then when it gets back to the first page the drop to will populate with the session or the same client as when i left that page and the on change of the drop down will work.
Eric