开发者

PHP drop down and Session question

开发者 https://www.devze.com 2022-12-18 06:48 出处:网络
What really needs to happen here is.. A session takes my data from the drop down listed below. Its gonna take it to the process page then bring it back to this page with a header on the process page.

What really needs to happen here is.. A session takes my data from the drop down listed below. 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 dropdown 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. Can anyone help me with this. Thank you Right now this returns the client to the drop down but the onchange for the drop down does not work which is what I really need to work.

session_start();


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


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


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


    $sel=($id==$current)?'SELECTED':'';

    $options4.="<OPTION $sel VALUE=\"$value\">".$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>

Process page header

session_start();
$_SESSION['ClientNamefour'] = $_POST['txtclientcode'];

// Do the redirect





// Do the redirect
header("Location: test.php");
exit();


I don't know your question or problem but I just guess that it should be

$_SESSION['ClientNamefour'] = $_POST['ClientNamefour'];

instead of

$_SESSION['ClientNamefour'] = $_POST['txtclientcode'];

Also don't forget to put closing </option> tags into your code.

Of course you have to send the the form data to the process page, but

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

looks like the data gets send back to the same page.

And never trust data submitted by the user.

Edit:

Try:

onChange="Javascript:document.forms[0].submit()"

or

onChange="Javascript:document.forms['form'].submit()"

But that is only what I found using Google.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号