Php 数据未在MYSQL数据库中发布?
我正在尝试使用RESTAPI在MySQL数据库中创建新记录。但是,$data中存储的数据不包含我通过参数输入的任何值 我试图回显/打印以查看它包含的内容,但它什么都没有 网址:。 我可以获取数据,但不能发布Php 数据未在MYSQL数据库中发布?,php,api,mysqli,Php,Api,Mysqli,我正在尝试使用RESTAPI在MySQL数据库中创建新记录。但是,$data中存储的数据不包含我通过参数输入的任何值 我试图回显/打印以查看它包含的内容,但它什么都没有 网址:。 我可以获取数据,但不能发布 function insertQueue() { global $connection; $data = json_decode(file_get_contents('php://input'), true); echo $data; var_dump($d
function insertQueue()
{
global $connection;
$data = json_decode(file_get_contents('php://input'), true);
echo $data;
var_dump($data);
$firstname = $data["userName"];
$lastname = $data["lastname"];
$organization = $data["organization"];
$type = $data["type"];
$service = $data["service"];
echo $query="INSERT INTO queue SET
firstname='".$firstname."',
lastname='".$lastname."',
organization='".$organization."',
type='".$type."',
service='".$service."'";
if(mysqli_query($connection, $query))
{
$response=array(
'status' => 1,
'status_message' =>'Added to queue successfully.'
);
}
else
{
$response=array(
'status' => 0,
'status_message' =>'Queue Insertion has failed.'
);
}
header('Content-Type: application/json');
echo json_encode($response);
}
以下不是有效的URL。如果要同时发送这两个,则需要使用
&
:
http://localhost/api/v1/test.php?firstname=Yacub?lastname=Ali
上面的正确选项是:
http://localhost/api/v1/test.php?firstname=Yacub&lastname=Ali
其次,这是一个GET
请求。POST
请求将不包含任何查询字符串。因此,将您的
方法更改为POST
:
<form action="my.php" method="post">
<!--------------------^^^^^^^^^^^^^
您只需使用:
$data = $_POST; // After you convert the form method to POST.
以下不是有效的URL。如果要同时发送这两个,则需要使用
&
:
http://localhost/api/v1/test.php?firstname=Yacub?lastname=Ali
上面的正确选项是:
http://localhost/api/v1/test.php?firstname=Yacub&lastname=Ali
其次,这是一个GET
请求。POST
请求将不包含任何查询字符串。因此,将您的
方法更改为POST
:
<form action="my.php" method="post">
<!--------------------^^^^^^^^^^^^^
您只需使用:
$data = $_POST; // After you convert the form method to POST.
哎哟这是一些令人讨厌的SQL注入攻击潜力:('php://input“看起来很奇怪,不是有效的filepath@halojoy哎哟。这是一些令人讨厌的SQL注入攻击潜力:('php://input“看起来很奇怪,不是有效的filepath@halojoy您好@Praveen Kumar,我没有使用表单执行POST请求。我正在尝试通过URL插入数据。@YacubAli然后它是一个
GET
request mate。您好@Praveen Kumar,我没有使用表单执行POST请求。我正在尝试通过URL插入数据。@YacubAli然后它是一个获取
请求配偶。