php PHP通过href将输入值传递到另一个页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21037743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:45:40  来源:igfitidea点击:

PHP Passing Input values through href to another page

php

提问by Rohit Dubey

 <input type="text" name="a" id="a" />
 <a href="xxx.php?id = <? echo '$data['id']' ?>&mk=">CLICK</a>

Now this is my question that can we pass an input tag value of HTML to 'mk' so that value can be used in the next page for process. Though i have done my project in a different way but still i want to know wether is it possible to do so . I have searched a lot but none of the question is same as i got so plz help me out. And i dnt want to use form so i just want to know can we pass this value using href tag r not.

现在这是我的问题,我们是否可以将 HTML 的输入标记值传递给“mk”,以便该值可以在下一个页面中用于处理。虽然我以不同的方式完成了我的项目,但我仍然想知道是否有可能这样做。我已经搜索了很多,但没有一个问题与我得到的相同,所以请帮助我。而且我不想使用表单,所以我只想知道我们是否可以使用 href 标签 r 传递这个值。

This is the code i have

这是我的代码

<form  method="post">
    <table align="center" bgcolor="#FFFFCC" border="1">
        <tr><th>ID</th><th>PRODUCT</th><th>PRICE</th><th>DATE OF POST</th><th>PHONE NUMBER</th><th>AUTHENTICATE</th></tr>
        <?
        $sel = mysql_query("SELECT * FROM addunauth WHERE adminauthorize = 'uncheck'") or die("CANNOT FETCH DATA FOR ADMIN " . mysql_error());
        if (mysql_num_rows($sel) > 0) {
            while ($data = mysql_fetch_array($sel)) {
                ?>      <tr>
                    <td><? echo $data['id']; ?></td>
                    <td><? echo $data['product_name']; ?></td>
                    <td><? echo $data['product_sp']; ?></td>
                    <td><? echo $data['product_time']; ?></td>
                    <td><? echo $data['phoneNumber']; ?></td>
                    <td><input type="text" name="a" id="a" /></td>


                    <td align="center">
                        <a href="processadminTask.php?id=<? echo $data['id']; ?>&mk=" >
                            AUTHENTICATE
                        </a>
                    </td>
                </tr>
    <?
    }
} else {
    ?>          <tr><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr>

        <? }
        ?>
    </table>

</form>

Now just tell me how to pass the input value

现在告诉我如何传递输入值

采纳答案by Roopendra

Your variable not parse inside single quotes. your <? echo '$data['id']' ?>should be <?php echo $data['id'] ?>

您的变量不会在单引号内解析。你<? echo '$data['id']' ?>应该是<?php echo $data['id'] ?>

 <input type="text" name="a" id="a" />
 <a href="xxx.php?id = <?php echo $data['id'] ?>&mk=">CLICK</a>"
 <a id="link" href="xxx.php?id=111&mk=">CLICK</a>

Edit:-simply add one more hidden fields to store id value as well and get value in js and assign to href

编辑:-只需添加一个隐藏字段来存储 id 值,并在 js 中获取值并分配给 href

 <input type="text" name="idval" id="idval" value="100" />
 <input type="hidden" name="mk" id="mkval" value="101" />  

Js:-

Js:-

var idval = $('#idval').val();
var mk = $('#mkval').val();
var link = 'xxx.php?id=' + idval + '&mk=' + mk;

$("#link").attr("href", link);

Working Demo

Working Demo

回答by Hanky Panky

<? echo '$data['id']' ?>

Is wrong PHP Syntax

是错误的 PHP 语法

Use

<?php echo $data['id']; ?>

Like:

喜欢:

<a href="xxx.php?id=<?php echo $data['id']; ?>&mk=">CLICK</a>

回答by rccoros

Your

您的

<? echo '$data['id']' ?>

is not correct. You can actually use something like this

是不正确的。你实际上可以使用这样的东西

<?= $data['id'] ?>

so you'll have

所以你会有

<a href="xxx.php?id = <?= $data['id'] ?>&mk=">CLICK</a>"

回答by codename_subho

I think it is possible with javascript:

我认为使用 javascript 是可能的:

 getElementById('id of html input').value

This will get you the input value and then you can assign it to 'mk' So you can check with it

这将为您提供输入值,然后您可以将其分配给 'mk' 所以您可以检查它

回答by Hemant

Try this

尝试这个

<?php
$data['id'] = 2;
?>
<html>
 <input type="text" name="a" id="a" />
 <a href="xxx.php?id=<?=$data['id'];?>&mk=">CLICK</a>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script >
$(document).ready(function(){

$('a[href]').click(function(event){
    event.preventDefault();
    event.stopPropagation();
    var inputTagID = $('#a').val();
    var hrefVal = this.toString().replace("&mk=", "&mk="+inputTagID); 
    window.location = hrefVal;
});
});
</script>
</html>