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();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?