POST 方法变量未通过
POST method variable not passing
我正在尝试制作一个简单的 "request register app",因此我通过 POST 将变量 $appUser_id 发送到一个 .php 文件,该文件将进行存储入数据库。我工作了一段时间,但后来它停止工作了,我不知道我改变了什么。它在数据库中注册,但将 appUser_id 设置为 0,但我正在发送一个号码。
它不会抛出任何错误,但不会获取正确的变量值。
现在用 Postman 发送数据。
newRequest.php
<?php
if($_SERVER["REQUEST_METHOD"]=="POST"){
require 'connection.php';
makeRequestRegister();
}
function makeRequestRegister()
{
global $connect;
$appUser_id = $_POST["appUser_id"];
$query = "INSERT INTO requests (appUser_id) VALUES ('$appUser_id')";
mysqli_query($connect, $query) or die (mysqli_error($connect));
mysqli_close($connect);
}
?>
Connection.php
<?php
define('hostname', 'localhost');
define('user', 'root');
define('password', 'password');
define('databaseName', 'belandri_TEII');
$connect = mysqli_connect(hostname, user, password, databaseName);
?>
邮递员
数据库
Pd:忘掉注入和那种保护吧。我暂时不关心这个。
您当前正在使用 Headers
选项卡,但是您应该为 POST 数据使用 Body
选项卡。
查看以下示例:
如果您查看 Postman documentation,您会发现有几种构建请求正文的方法:
表单数据
multipart/form-data is the default encoding a web form uses to transfer data. This simulates filling a form on a website, and submitting it. The form-data editor lets you set key/value pairs (using the key-value editor) for your data. You can attach files to a key as well. Do note that due to restrictions of the HTML5 spec, files are not stored in history or collections. You would have to select the file again at the time of sending a request.
urlencoded
This encoding is the same as the one used in URL parameters. You just need to enter key/value pairs and Postman will encode the keys and values properly. Note that you can not upload files through this encoding mode. There might be some confusion between form-data and urlencoded so make sure to check with your API first.
原始
A raw request can contain anything. Postman doesn't touch the string entered in the raw editor except replacing environment variables. Whatever you put in the text area gets sent with the request. The raw editor lets you set the formatting type along with the correct header that you should send with the raw body. You can set the Content-Type header manually as well. Normally, you would be sending XML or JSON data here.
二进制
binary data allows you to send things which you can not enter in Postman. For example, image, audio or video files. You can send text files as well. As mentioned earlier in the form-data section, you would have to reattach a file if you are loading a request through the history or the collection.
看起来您可能正在 headers 中发送 post 变量。请改用 body 选项卡。
您在查询中将 $appUser_id 作为字符串传递,您不需要在变量周围加上单引号,因为 双引号 计算里面的变量。你可以这样做:
$query = "INSERT INTO requests (appUser_id) VALUES ($appUser_id)";
或者
$query = "INSERT INTO requests (appUser_id) VALUES (".$appUser_id.")";
我正在尝试制作一个简单的 "request register app",因此我通过 POST 将变量 $appUser_id 发送到一个 .php 文件,该文件将进行存储入数据库。我工作了一段时间,但后来它停止工作了,我不知道我改变了什么。它在数据库中注册,但将 appUser_id 设置为 0,但我正在发送一个号码。
它不会抛出任何错误,但不会获取正确的变量值。
现在用 Postman 发送数据。
newRequest.php
<?php
if($_SERVER["REQUEST_METHOD"]=="POST"){
require 'connection.php';
makeRequestRegister();
}
function makeRequestRegister()
{
global $connect;
$appUser_id = $_POST["appUser_id"];
$query = "INSERT INTO requests (appUser_id) VALUES ('$appUser_id')";
mysqli_query($connect, $query) or die (mysqli_error($connect));
mysqli_close($connect);
}
?>
Connection.php
<?php
define('hostname', 'localhost');
define('user', 'root');
define('password', 'password');
define('databaseName', 'belandri_TEII');
$connect = mysqli_connect(hostname, user, password, databaseName);
?>
邮递员
数据库
Pd:忘掉注入和那种保护吧。我暂时不关心这个。
您当前正在使用 Headers
选项卡,但是您应该为 POST 数据使用 Body
选项卡。
查看以下示例:
如果您查看 Postman documentation,您会发现有几种构建请求正文的方法:
表单数据
multipart/form-data is the default encoding a web form uses to transfer data. This simulates filling a form on a website, and submitting it. The form-data editor lets you set key/value pairs (using the key-value editor) for your data. You can attach files to a key as well. Do note that due to restrictions of the HTML5 spec, files are not stored in history or collections. You would have to select the file again at the time of sending a request.
urlencoded
This encoding is the same as the one used in URL parameters. You just need to enter key/value pairs and Postman will encode the keys and values properly. Note that you can not upload files through this encoding mode. There might be some confusion between form-data and urlencoded so make sure to check with your API first.
原始
A raw request can contain anything. Postman doesn't touch the string entered in the raw editor except replacing environment variables. Whatever you put in the text area gets sent with the request. The raw editor lets you set the formatting type along with the correct header that you should send with the raw body. You can set the Content-Type header manually as well. Normally, you would be sending XML or JSON data here.
二进制
binary data allows you to send things which you can not enter in Postman. For example, image, audio or video files. You can send text files as well. As mentioned earlier in the form-data section, you would have to reattach a file if you are loading a request through the history or the collection.
看起来您可能正在 headers 中发送 post 变量。请改用 body 选项卡。
您在查询中将 $appUser_id 作为字符串传递,您不需要在变量周围加上单引号,因为 双引号 计算里面的变量。你可以这样做:
$query = "INSERT INTO requests (appUser_id) VALUES ($appUser_id)";
或者
$query = "INSERT INTO requests (appUser_id) VALUES (".$appUser_id.")";