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 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测