The parameters passed after the action attribute in the form cannot be obtained.

小云云
Release: 2023-03-19 21:38:01
Original
1472 people have browsed it

This article mainly brings you a solution to the problem that the parameters passed behind the action attribute in the form cannot be obtained. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look, I hope it can help everyone.

is as follows:


$p_id = $_REQUEST['p_id'];

echo "<h1>您将更新商品编号为<span>$p_id</span>的商品信息 <a href=&#39;listproduct.php&#39;>查看所有</a></h1>
<form action=&#39;updateproduct.do.php?p_id=$p_id&#39; method=&#39;get&#39;> 
 商品名称:<input type=&#39;text&#39; name=&#39;p_name&#39; value=&#39;".$result_name2["name"]."&#39;>商品名称小于10个字<br><br>
 商品价格:<input type=&#39;text&#39; name=&#39;p_price&#39; value=&#39;".$result_price2["price"]."&#39;>价格大于0且小于99999.99(保留两位小数)<br><br>
 图片:<input type=&#39;text&#39; name=&#39;p_pic&#39; value=&#39;".$result_pic2["pic"]."&#39;>请输入图片src<br><br>
 生产日期:<input type=&#39;text&#39; name=&#39;p_date&#39; value=&#39;".$result_onShelfDate2["onShelfDate"]."&#39;>格式:yyyy-mm-dd<br><br>
 详细信息:<input type=&#39;text&#39; name=&#39;p_detail&#39; value=&#39;".$result_detail2["detail"]."&#39;>详细信息请保持在50字以内<br><br>
 <button>提交</button>
</form>";
?>
Copy after login

As shown in the above code, I want to submit it by clicking the button While jumping to updateproduct.do.php, pass the $p_id obtained on this page to the next page through the url value. But every time after clicking the button, there is only in the address bar “updateproduct.do.php?p_name=11&p_price=22&p_pic=33&p_date=44&p_detail=55”

##What about p_id It can't be passed on. After struggling for a long time, the reason is actually very simple. (The following is my personal understanding, but the problem is solved) Under method=get, the form only receives the form element "name" attribute and the corresponding "value". Want to write it yourself in the action? Pass the value in the form, the value of method must be =post, that is, the second line in the code is changed to:


<form action=&#39;updateproduct.do.php?p_id=$p_id&#39; method=&#39;post&#39;>
Copy after login
Just change it to this!

Related recommendations:


JS function passing parameters by value

php reference definition and reference passing parameter example usage detailed explanation

Detailed explanation of basic syntax of php function and usage examples of passing parameters

The above is the detailed content of The parameters passed after the action attribute in the form cannot be obtained.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template