【发布时间】:2020-01-28 15:19:40
【问题描述】:
我是 PHP 新手,我正在为我在大学的一门学科开发一个简单的客户端。该客户端的主要目标是将 CRUD 转换为 JAVA API。经过一番研究,我发现对于像这样的简单客户端,人们使用 CURL。我从未使用过 curl,我不知道我是否做错了什么。当我提交表单时,我收到此错误。
“注意:未定义的索引:名称”
“注意:未定义的索引:描述”
我能做些什么来解决这个问题?如果有人可以帮助我,我将不胜感激!
HTML 表单
<form class="form" action="createActivity.php">
<label for="name" class="labelActivityName"><b>Name</b></label>
<input type="text" id="name" placeholder="Name" name="name">
<label for="comment" class="labelActivityDescription"><b>Description</b></label>
<textarea id="description" placeholder="Description..." name="description"></textarea>
<button type="submit"><b>Submit</b></button>
</form>
PHP
$url = "http://localhost:8080/tourism/api/activities";
$username = 'user';
$password = 'user123';
$fields = array(
'name' => $_POST['name'],
'description' => $_POST['description']
);
$client = curl_init();
curl_setopt($client, CURLOPT_URL, $url);
curl_setopt($client, CURLOPT_RETURNTRANSFER,1);
curl_setopt($client, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($client, CURLOPT_USERPWD, "$username:$password");
curl_setopt($client, CURLOPT_POST, count($fields));
curl_setopt($client, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($client);
curl_close($client);
【问题讨论】: