admin管理员组文章数量:1122846
I have a little API script
I'm trying to post from a form on the same page ACTIVE or SUSPENDED.
But show text in the curl script. but its not showing $variable and just the code I put in
<?php
$variable = $_POST['name'];
echo $variable;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '....');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer ...',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "state": "<?php echo $variable; ?>"}');
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
?>
<form method="POST" action="suspend.php">
<input type="text" name='name' value="some value">
<button type="submit">Go</button>
</form>
I have a little API script
I'm trying to post from a form on the same page ACTIVE or SUSPENDED.
But show text in the curl script. but its not showing $variable and just the code I put in
<?php
$variable = $_POST['name'];
echo $variable;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '....');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer ...',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "state": "<?php echo $variable; ?>"}');
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
?>
<form method="POST" action="suspend.php">
<input type="text" name='name' value="some value">
<button type="submit">Go</button>
</form>
Share
Improve this question
edited Nov 23, 2024 at 16:53
halfer
20.4k19 gold badges108 silver badges200 bronze badges
asked Nov 21, 2024 at 20:00
David RowlandDavid Rowland
172 bronze badges
1 Answer
Reset to default 0<?php echo
doesn't work inside a string. It only works after you've exited PHP mode with ?>
.
Create an array containing the variable and use json_encode()
.
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(["state" => $variable]));
本文标签: PHP form post POST amp showing in curlStack Overflow
版权声明:本文标题:PHP form post $_POST & showing in curl - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307519a1933339.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论