dp0518 2016-10-24 16:42
浏览 23
已采纳

表单提交返回'array'

I'm trying to send through POST the name of some hotels, the code, and the e-mail address to a new page that will send an email to the checked hotels. So far, though, what I'm really trying to do it send the data to a new php which only echos them. What I've worked on so far is:

<form action='chior.php' method='post'>
<?php
$i = 0;
foreach($counter as $obj => $nr_rez) {
    $nume_hotel = $hoteluri[$obj];
    $localitate = $localitati[$obj];       //all this arranges the data from a sql query
    $email       = $emailuri[$obj];
    $total_rez += $nr_rez;
    $cprest     = substr($cprest, 3, 10);
    $parametri  = "cp=$cprest&dstart=$data_start_af&dstop=$data_stop_af";
    $email      = str_replace(";", ";
", $email);

    echo "<tr class='mainRow'> <td> $i </td> 
               <td><input type='text' name='hotelul[$i][]' value='".$cprest."' readonly/> </td> 
               <td><a href='link.php?$parametri' target='_blank'>$nume_hotel</a></td> 
               <td> $localitate </td> 
               <td> $nr_rez </td> 
               <td><input type='text' name='hotelul[$i][]' value='". $email ."'/></td>
               <td><input type='checkbox' id='$i' name='hotelul[$i][]'/></td>
          </tr>";
$i++;
}
?>
<input type='submit'/> </form>

There's a bit of the page I haven't posted, for brevity's sake (various tags and css elements to make the page look nicely), but it works on my end. The only problem is that the page I'm sent to after clicking submit - chior.php, which looks like this <?php echo $_POST['hotelul'];?>, returns 'Array'. I've also tried <?php echo implode('/', $_POST['hotelul']);?> , <?php echo implode('-', implode('/', $_POST['hotelul']));?> , <?php echo $_POST['hotelul[][]'] , which was pretty much all I could think of and it still did not work. Does anyone have any ideea why that is and how I could fix this? Thanks.

  • 写回答

2条回答 默认 最新

  • doubeng1278 2016-10-24 18:42
    关注

    Changes

    1) Change name='hotelul[$i][]' to name='hotelul[]'

    2) All input names are hotelul. Change to some other name to avoid ambiguity.

    Updated Code:

    <form action='chior.php' method='POST'>
      <?php
      $i = 0;
      foreach($counter as $obj => $nr_rez) {
        $nume_hotel = $hoteluri[$obj];
        $localitate = $localitati[$obj];
        $total_rez += $nr_rez;
        $cprest     = substr($cprest, 3, 10);
        $parametri  = "cp=$cprest&dstart=$data_start_af&dstop=$data_stop_af";
        $email      = str_replace(";", ";
    ", $emailuri[$obj]);
    
        echo "<tr class='mainRow'>
                <td> $i </td> 
                <td><input type='text' name='hotelul[]' value='".$cprest."' readonly/> </td> 
                <td><a href='link.php?$parametri' target='_blank'>$nume_hotel</a></td> 
                <td> $localitate </td> 
                <td> $nr_rez </td> 
                <td><input type='text' name='hotelul_email[]' value='". $email ."'/></td>
                <td><input type='checkbox' id='$i' name='hotelul_chkbox[]'/></td>
              </tr>";
        $i++;
      }
      ?>
      <input type='submit'/>
    </form>
    

    chior.php

    <?php
    $checkedHotels = sizeof($_POST['hotelul_chkbox']);
    for($i = 0 ; $i < $checkedHotels; $i++){
      $checked_hotel_email = $_POST['hotelul_email'][$i];
    
      //Write your mail function here to send mail to all checked hotels using `$checked_hotel_email`.
    
    }?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100