dongzhuanlei0768 2011-08-23 02:05
浏览 171
已采纳

PHP通过URL传递变量

I understand how a PHP URL works - I think ... but I'm having problems getting the actual value of the variable to be passed in the example below.

Example

Note: I am adding the below form into a data cell (as part of a table being read via PHP).

$currentrowid = 1;

echo '<td>
  <div class="editdelete">
    <form action="phpindex.php?page=edit&thisrow=<?php echo $currentrowid;?>" method="post">
      <input type="submit" value="Edit" >
    </form>
  </div>
</td>';

... Some other section of code to read the URL output by the form above:

$val = $_POST['thisrow']; 
echo "the value is: " .$val; //Outputs "$currentrowid"

So, as you can see the code returns the actual name of the variable being passed, NOT the value of the variable being passed.

Any ideas here?

  • 写回答

4条回答 默认 最新

  • douke6027 2011-08-23 02:07
    关注

    Since you are already within a PHP block, you should not wrap your variable within <?php ... ?>. This will give you an error.

    To make this work, you can choose 1 of 2 options:

    1) String Concatenation:

    echo '... <form action="phpindex.php?page=edit&thisrow='.$currentrowid.'" method="post"> ...';
    

    2) Wrap your string in " (double quotes) instead of ' (single quotes):

    echo "... <form action=\"phpindex.php?page=edit&thisrow=$currentrowid\" method=\"post\"> ...";
    

    Note that the second method forces you to escape all the double quotes inside of your string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号