doukuai3822 2019-02-21 08:09
浏览 7
已采纳

$ _SESSION没有在表单上选择正确的值

I'm trying to store a $_SESSION variable on a form option for further use on the next page after submit (which will be reloaded and used multiple times after that, so a simple $_POST won't do)

the problem is that it doesn't matter what option I choose, it always saves the value from the last option ("Victoria" in this case) as if I picked that one.

session_start(); is already declared on top of the page

Am I missing something? Here is the form:

<form method="post">

  <label for="turno">Turno:</label>
  <select name="turno" id="turno">
  <option value=DIA>Dia</option>
  <option value=NOCHE>Noche</option>
  </select>
  <label for="planillera">Planillera:</label>
  <select name="planillera" id="planillera">
  <option value="<?php $_SESSION['planillera']  = 'Rosa'; ?>">Rosa</option>
  <option value="<?php $_SESSION['planillera']  = 'Cristina'; ?>" >Cristina</option>
  <option value="<?php $_SESSION['planillera']  = 'Maria'; ?>" >Maria</option>
  <option value="<?php $_SESSION['planillera']  = 'Romina'; ?>">Romina</option>
  <option value="<?php $_SESSION['planillera']  = 'Julieta'; ?>" >Julieta</option>
  <option value="<?php $_SESSION['planillera']  = 'Victoria'; ?>" >Victoria</option>
  </select>

<input type="submit" id='enviar' value="Registrar viaje" formaction="registrar_viaje.php">


</form>

</div>
  • 写回答

1条回答 默认 最新

  • dsvf46980 2019-02-21 08:13
    关注

    That's not how $_SESSION or select works.

    What you are doing is simply executing PHP where you set value of $_SESSION multiple times - hence why it always assigns the last value.

    Your select should look like this:

      <select name="planillera" id="planillera">
      <option value="Rosa">Rosa</option>
      <option value="Cristina">Cristina</option>
      <option value="Maria">Maria</option>
      <option value="Romina">Romina</option>
      <option value="Julieta">Julieta</option>
      <option value="Victoria">Victoria</option>
      </select>
    

    Then in the inside of registrar_viaje.php you would do:

    $_SESSION['plankillera'] = $_POST['planillera'];
    

    Lastly, you would do a redirect to another page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看