dongxun7962 2013-07-24 11:38
浏览 43

php选择下拉选择到会话变量

I have two dropdown boxes and I want the user to choose values from both. The dropdown boxes are filled with results of a query on page load. I want these values to then be stored as a session variable for use in subsequent queries.

First file = choose.php

<html>
    <form action="choose2.php" method="post">
    <?//db connection stuff taken out from here
        }
// fill classes      
    $result = mysqli_query($con,"SELECT * FROM classes");                                            
    echo "<select id='classlist'>";

    while($row = mysqli_fetch_array($result))
        {
        echo " <option value=" . $row['id'] . ">" . $row['classname'] . "</option>";
        }
    echo "</select>";

    //fill schemes of work
    $result = mysqli_query($con,"SELECT * FROM schemes_of_work");
    echo "<select id='sowlist'>";

    while($row = mysqli_fetch_array($result))
        {
        echo " <option value=" . $row['id'] . ">" . $row['name'] . "</option>";
        }
    echo "</select>";

    mysqli_close($con);
    ?>   
<input type="submit">
</form> 
</html>

second file = choose2.php

 <?php  session_start(); 
    $_SESSION['classname'] = $_POST["classlist"];
    $_SESSION['sowname'] = $_POST["sowlist"];
    ?>

    <?php echo $_SESSION['classname'];?>
    <?php echo $_SESSION['sowname'];?>

I cant get this to work though - I am getting an empty page on choose2 and the following error in apache log: "Undefined index: sowlist in /var/www/assessment/choose2.php on line 3,

  • 写回答

1条回答 默认 最新

  • doufan9805 2013-07-24 11:41
    关注

    The select tag should have a name attribute to be able to use it in php POST. Try

    <select id='classlist' name="classlist">
    

    The same for the other one.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line