dongyou6768 2015-01-28 12:05
浏览 44
已采纳

使用PHP从HTML中检索变量变量

I am creating a HTML page that creates a large excel database, and gives the user the option to search and display the contents filtering certain parameters. This works great so far, however now I am trying to add the option to update the excel database based on user input from the user changing the generated textboxes in the HTML page. When my php generates the textboxes I had it generate the name of the textbox as the name of the cell it pulled the data from. Now when trying to pull the changed data from the html text box, I would like to use $_GET[$cell], cell being the variable in php which runs in a loop to generate the names of each cell or corresponding labeled html textbox. I know this cannot be done this way, which is why I am looking for an alternative. Any ideas? -Thank you

<html>
<head>
<meta http-equiv="Content-Type" content="text/html"; charset=ISO-8859-1">
                                                                        
                                                                    
   <button type ="submit" name="Submit" value="Revise" onclick="f1.action='Revise.php';return true;"> Revise </button>
                                                                                                    
                                                                                                    
<iframe width="4000" height="2000000" name="myiframe" src="Revise.php" method = "get"


    
    
        <tr>
    <td> <input type ='text' value= 'DLWR' name'C3'/></td><td> <input type ='text' value= 'DLWR' name'D3'/></td><td> <input type ='text' value= '2003' name'E3'/></td><td> <input type ='text' value= 'NS  ' name'F3'/></td><td> <input type ='text' value= 'NS  ' name'G3'/></td><td> <input type ='text' value= 'MTH' name'H3'/></td><td> <input type ='text' value= 'S ' name'I3'/></td><td> <input type ='text' value= '0' name'N3'/></td><td> <input type ='text' value= 'NS  ' name'O3'/></td><td> <input type ='text' value= '185400' name'P3'/></td><td> <input type ='text' value= 'E' name'R3'/></td><td> <input type ='text' value= 'LCS' name'S3'/></td><td> <input type ='text' value= 'O ' name'T3'/></td><td> <input type ='text' value= '52' name'Y3'/></td><td> <input type ='text' value= '187366' name'AA3'/></td><td> <input type ='text' value= '52' name'AC3'/></td><td> <input type ='text' value= '0' name'AD3'/></td><td> <input type ='text' value= '0.41' name'AE3'/></td><td> <input type ='text' value= '0' name'AG3'/></td><td> <input type ='text' value= '21.32' name'AH3'/></td><td> <input type ='text' value= '21.32' name'AK3'/></td><td> <input type ='text' value= '20140528' name'AO3'/></td><td> <input type ='text' value= '198097' name'AP3'/></td><td> <input type ='text' value= 'NS  ' name'AQ3'/></td><td> <input type ='text' value= 'E' name'AR3'/></td><td> <input type ='text' value= '4029176' name'AS3'/></td><td> <input type ='text' value= 'DLWR' name'C4'/></td><td> <input type ='text' value= 'DLWR' name'D4'/></td><td> <input type ='text' value= '2003' name'E4'/></td><td> <input type ='text' value= 'OHRY' name'F4'/></td><td> <input type ='text' value= 'OHRY' name'G4'/></td><td> <input type ='text' value= 'LCS' name'H4'/></td><td> <input type ='text' value= 'O ' name'I4'/></td><td> <input type ='text' value= '52' name'N4'/></td><td> <input type ='text' value= 'NS  ' name'O4'/></td><td> <input type ='text' value= '187366' name'P4'/></td><td> <input type ='text' value= 'E' name'R4'/></td><td> <input type ='text' value= 'LCB' name'S4'/></td><td> <input type ='text' value= 'S ' name'T4'/></td><td> <input type ='text' value= '63' name'Y4'/></td><td> <input type ='text' value= '187366' name'AA4'/></td><td> <input type ='text' value= '11' name'AC4'/></td><td> <input type ='text' value= '0' name'AD4'/></td><td> <input type ='text' value= '0.41' name'AE4'/></td><td> <input type ='text' value= '0' name'AG4'/></td><td> <input type ='text' value= '4.51' name'AH4'/></td><td> <input type ='text' value= '4.51' name'AK4'/></td><td> <input type ='text' value= '20140528' name'AO4'/></td><td> <input type ='text' value= '198097' name'AP4'/></td><td> <input type ='text' value= 'NS  ' name'AQ4'/></td><td> <input type ='text' value= 'E' name'AR4'/></td><td> <input type ='text' value= '4029176' name'AS4'/></td><td> <input type ='text' value= 'DLWR' name'C5'/></td><td> <input type ='text' value= 'DLWR' name'D5'/></td><td> <input type ='text' value= '2003' name'E5'/></td><td> <input type ='text' value= 'OHRY' name'F5'/></td><td> <input type ='text' value= 'OHRY' name'G5'/></td><td> <input type ='text' value= 'LCB' name'H5'/></td><td> <input type ='text' value= 'S ' name'I5'/></td><td> <input type ='text' value= '63' name'N5'/></td><td> <input type ='text' value= 'OHRY' name'O5'/></td><td> <input type ='text' value= '187366' name'P5'/></td><td> <input type ='text' value= 'L' name'R5'/></td><td> <input type ='text' value= 'LCS' name'S5'/></td><td> <input type ='text' value= 'P ' name'T5'/></td><td> <input type ='text' value= '63' name'Y5'/></td><td> <input type ='text' value= '187366' name'AA5'/></td><td> <input type ='text' value= '0' name'AC5'/></td><td> <input type ='text' value= '0' name'AD5'/></td><td> <input type ='text' value= '0.41' name'AE5'/></td><td> <input type ='text' value= '0' name'AG5'/></td><td> <input type ='text' value= '0' name'AH5'/></td><td> <input type ='text' value= '0' name'AK5'/></td><td> <input type ='text' value= '20140603' name'AO5'/></td><td> <input type ='text' value= '306552' name'AP5'/></td><td> <input type ='text' value= 'NS  ' name'AQ5'/></td><td> <input type ='text' value= 'L' name'AR5'/></td><td> <input type ='text' value= '4021125' name'AS5'/>
    <br />
    </iframe>
        
    
</body>
</html>

And the PHP portion that calls each textbox individually would look like this in a perfect world:

 for($n=1; $n<27; $n++){
  $cell = $x . $y; 

   if(isset($_GET[$cell])){
   $string = $_GET[$cell];
    }
    else{ 
    break 1;
    }
 $objWorksheet ->getCell($cell) ->setValue($string);

  echo "<td> <input type ='text' value= '$string' name = '$cell'/></td>";

  $x=++$x;
  }
</div>
  • 写回答

1条回答 默认 最新

  • dongtiao2105 2015-01-28 12:13
    关注

    try it first with a normal form mechanism in html and as backend php, afterwards you can change it without any big changes to use ajax or so.

    <form method="POST" action="backend.php" id="excelform">
       <input type="text" value="foo" name="D3" /> 
       <button type="submit">Submit</button>
    </form>
    

    your backend.php could look like:

    <?php
    $cell = "D3";
    
    var_dump($_POST[$cell]);
    die();
    

    after you get this working you can send your data via an AJAX call (with jQuery) do:

    $("#excelform").submit(function( event ) {
    
      var form = $("#excelform");
      $.post(form.attr("action"), form.serialize()).done(function( data ) {
         alert( "Data Loaded: " + data );
      });
    
      //prevent the form to really send to another page
      event.preventDefault();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 能给我一些人生建议吗
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到
  • ¥15 请教一下,openwrt如何让同一usb储存设备拔插后设备符号不变?
  • ¥30 使用quartz框架进行分布式任务定时调度,启动了两个实例,但是只有一个实例参与调度,另外一个实例没有参与调度,不知道是为什么?请各位帮助看一下原因!!
  • ¥50 怎么获取Ace Editor中的python代码后怎么调用Skulpt执行代码
  • ¥30 fpga基于dds生成幅值相位频率和波形可调的容易信号发生器。
  • ¥15 R语言shiny包和ncdf4包报错
  • ¥15 origin绘制有显著差异的柱状图和聚类热图
  • ¥20 simulink实现滑模控制和pid控制对比,提现前者优势