duanke3985
2019-05-16 15:26
浏览 274
已采纳

如何在单击行特定按钮时将从数据库获取的记录值传递到另一个PHP页面

I m trying to pass the email fetched from database to next page based on the row button clicked. But i m not able to use inside the value attribute of tag.

i have created a button for each row. for any button clicked i want to move to a common page with row email. the email varies based on selected button.

while($row= mysqli_fetch_assoc($results))
{
   $_email=$row["email"];
   echo  "<tr><td>". $row["email"] ."</td><td>" . $row["name"] .
   "</td><td>". $row["credit"] ."</td><td>".
   '<form method="post" action="user.php">
    <input type="hidden" name="data" value="<?php echo $_email?>"/>
    <button><b>Home<b></button>
    </form>'. "</td></tr>";
}

the email corresponding to the row button should be avialable in user.php file using $_POST method. i m not getting email value when i m doing $data=$_POST["data"] in the user.php page

图片转代码服务由CSDN问答提供 功能建议

我试图根据点击的行按钮将从数据库中提取的电子邮件传递到下一页。 但是我无法在tag的value属性中使用。

我为每一行创建了一个按钮。 对于任何单击的按钮,我想移动到包含行电子邮件的公共页面。 电子邮件因所选按钮而异。

  while($ row = mysqli_fetch_assoc($ results))
 {
 $ _email = $ row [“email”]; \  n echo“&lt; tr&gt;&lt; td&gt;”。  $ row [“email”]。“&lt; / td&gt;&lt; td&gt;”  。  $ row [“name”]。
“&lt; / td&gt;&lt; td&gt;”。  $ row [“credit”]。“&lt; / td&gt;&lt; td&gt;”。
'&lt; form method =“post”action =“user.php”&gt; 
&lt; input type =“hidden”  name =“data”value =“&lt;?php echo $ _email?&gt;”/&gt; 
&lt; button&gt;&lt; b&gt; Home&lt; b&gt;&lt; / button&gt; 
&lt; / form&gt;'。  “&lt; / td&gt;&lt; / tr&gt;”; 
} 
   
 
 

对应于行按钮的电子邮件应该在user.php文件中使用$可用 _POST方法。 当我在user.php页面中执行$ data = $ _ POST [“data”]时,我没有收到电子邮件值

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douwan4993 2019-05-16 15:35
    已采纳

    If you use a double quote outer wrapper and then single quotes inside that wrapper for the attributes, it easier to read and debug.

    Also remember that if you have an assoc array and you want to place $row["email"] inside the double quoted string literal, you can leave the " off like this $row[email]

    See your edited code below

       $_email=$row["email"];
       echo 
        "<tr>
            <td>$row[email]</td>
            <td>$row[name]</td>
           <td>$row[credit]</td>
           <td>
                <form method='post' action='user.php'>
                    <input type='Hidden' name='data' value='$_email'/>
                    <button><b>Home<b></button>
                </form>
            </td>
        </tr>";
    
    点赞 打赏 评论

相关推荐 更多相似问题