Home > Backend Development > PHP Problem > What to do if php submission parameters are garbled

What to do if php submission parameters are garbled

藏色散人
Release: 2023-03-17 08:40:01
Original
1740 people have browsed it

Solution to garbled php submission parameters: 1. Open the corresponding PHP file; 2. Check the "$_POST["pro_name"]" code; 3. Modify the content to "echo '';" is enough.

What to do if php submission parameters are garbled

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What should I do if the php submission parameters are garbled?

Problem description:

PHP $_POST submits Chinese garbled characters

html:
<form action="__APP__/ShoppingCart/add" method="POST">
<br/><b>{$pro_name}</b><br/><br/>
价格:¥{$pro_price}<br/><br/>
已售出:{$pro_sale}件
数量<input type="text" size="2" name="pro_num" value="1"/><input type="submit" value="加入购物车" />
<input type="hidden" name="pro_id" value="{$pro_id}" />
<input type="hidden" name="pro_name" value="{$pro_name}" />
<input type="hidden" name="pro_price" value="{$pro_price}" />
</form>
action:
public function add(){
$user = session("user_name");
if(session("user_name")){
header("Content-Type:text/html;charset=utf8");
request.setCharacterEncoding("UTF-8");
$common = D("Common");
$data["user_id"] = $user[0]["user_id"];
$data["user_name"] = $user[0]["user_name"];
$data["pro_id"] = $_POST["pro_id"];
$data["pro_name"] = $_POST["pro_name"];
$data["pro_price"] = $_POST["pro_price"];
$data["pro_num"] = $_POST["pro_num"];
$data["pro_total"] = $_POST["pro_num"]*$_POST["pro_price"];
dump($data);
echo $data["pro_name"];
}
}
Copy after login

Why is the received $_POST["pro_name"] garbled? I have checked the source code of the page and the hidden field has not become garbled

Solution:

header("Content-Type:text/html;charset=utf8");
Copy after login

is changed to

echo &#39;<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">&#39;;
Copy after login

Recommended study: " PHP video tutorial

The above is the detailed content of What to do if php submission parameters are garbled. 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