duanbei1709 2015-08-28 12:29
浏览 14
已采纳

得到形式不传递值PHP

I have been searching and trying to find what is wrong with my code for quite a while and I wouldn't be asking this if I still had no idea what is wrong with my code. Essentially I am echoing a get form, with a php script as it's action like this:

<?php
//Add a team list and list members to each team.
$memq = "SELECT members.id, teams.team_name, teams.stage, teams.points, members.member1 FROM members INNER JOIN teams ON teams.team_name=members.team_name";
$memres = mysql_query($memq) or die ('Couldnt display members'.mysql_error());
echo "<br> Teams, Stage & Members: <br>";
while ($memrow = mysql_fetch_assoc($memres))
{
    $team_name = $memrow['team_name'];
    echo "<form method='get' action='addOne.php'><input type='hidden' name='team_name' value='$team_name'><input type ='submit' name='team_name' value='+1'></form> ";
    echo "<form method='get' action='addTwo.php?team_name=$team_name' value='<?php echo $team_name;?>'><button type ='submit'>+2</button></form> ";
    echo "<form method='get' action='addTen.php?team_name=$team_name' value='<?php echo $team_name;?>'><button type ='submit'>+10</button></form> ";
    echo $memrow['id'] . " | " . $memrow['team_name'] . " | " . $memrow['stage'] . " | " . $memrow['member1'] . " | " . $memrow['points'] . "<br>";
    
}
?>

I have been playing around with it and have tried quite a variety of things (having the value = field in the form declaration and other such), but essenially when I check the inspector in the browser it says this:

<form method="get" action="addOne.php?team_name=asda">
  <input type="hidden" value="asda">
  <input type="submit" value="+1"></form>

So you can see that the value is actually set, but the form submission must not be working because the if statement in addOne.php ( if (isset($_GET['team_name'])) ) is always returning false.

Am I missing something very simple here? Help appreciated, thanks in advance. :)

</div>
  • 写回答

2条回答 默认 最新

  • dqk94069 2015-08-28 12:34
    关注

    The problem is that you are using GET variables in the action property of the form. If you set method='get' and a action with get variables there, they will be deleted and overwritten with the variables in the form. It should be following HTML:

    <form method="get" action="addOne.php">
        <input type="hidden" name="team_name" value="asda">
        <input type="submit" value="+1">
    </form>
    

    and the PHP should look like this:

    $team_name = $memrow['team_name'];
    echo "<form method='get' action='addOne.php'><input type='hidden' name='team_name' value='$team_name'><input type ='submit' value='+1'></form> ";

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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效