doukuai3822 2019-02-21 00: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 00: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部