注意:未定义的索引:发布时的名称

时间:2014-08-08 17:06:59

标签: php rest post

因此,我试图掌握如何制作/使用API​​的基础知识。所以我有一些代码应该检查名称是否应该是什么,然后返回10。所以这里是代码

$name = $_POST['name'];

//Set array
$status = array();


if(isset($name) || $name = "Bob"){
    $status['success'] = 1;
    echo json_encode($status);
}
else{
    $status['success'] = 0;
    echo json_encode($status);
}

然后我跳到PostMan发送POST,我做

http://localhost/index.php?name=Bob

但我最终得到的只是

( ! ) Notice: Undefined index: name in /Users/matt/Dropbox/API Server/index.php on line 3

第3行原来是$name = $_POST['name'];。任何帮助都会很棒

1 个答案:

答案 0 :(得分:1)

如果您从URL(index.php?name = Bob)获取值,则必须

$name = $_GET['name'];