如何解决它,我的脚本中缺少什么

时间:2017-05-18 07:20:22

标签: php sql-server

我有这个脚本

当我在Postman中测试时,我已经注意到了这个

如何解决? THQ

我有这个脚本

<?php

//creating response array
$response = array();

if($_SERVER['REQUEST_METHOD']=='POST'){

//getting values
$teamName = $_POST['name'];
$memberCount = $_POST['member'];


//including the db operation file
require_once '../includes/DbOperation.php';

$db = new DbOperation();

//inserting values
if($db->createTeam($teamName,$memberCount)){
    $response['error']=false;
    $response['message']='Team added successfully';
}else{

    $response['error']=true;
    $response['message']='Could not add team';
}

}else{
$response['error']=true;
$response['message']='You are not authorized';
}
echo json_encode($response);

<?

当我在Postman中测试时,我已经注意到了这个

<br/>
<b>Notice</b>: name in
<b>C:\xampp\htdocs\MyWebService\api\createteam.php</b> on line
<b>11</b>
<br/>
<br/>
<b>Notice</b>:  Undefined index: member in
<b>C:\xampp\htdocs\MyWebService\api\createteam.php</b> on line
<b>12</b>
<br />
{"error":true,"message":"Could not add team"}

如何解决? THQ

1 个答案:

答案 0 :(得分:0)

  

未定义索引:成员

$memberCount = $_POST['member'];

您在预期的POST数据中缺少“成员”值

我建议在使用之前检查值是否存在。

if (!isset($_POST['member'])) {
    throw new Exception("missing expected value \"member\" in POST");
}
$memberCount = $_POST['member'];