0

So I'm trying to grasp the basics of how to make/use an API. So I have a bit of code that should check if the name is what is should be, then return a 1 or 0. So here's the code

$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);
}

Then I hop over to PostMan to send the POST, I do

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

But all I end up getting is

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

Line 3 turns out to be $name = $_POST['name'];. Any help would be great

idris
  • 1,019
  • 1
  • 9
  • 22
  • The error means `$_POST['name']` has not been set. Is it supposed to be? When/where do you set it? – Mark Miller Aug 08 '14 at 17:10
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – CBroe Aug 08 '14 at 17:18
  • Unrelated to the issue you're having, but in your `if` statement, you need to use `$name == "Bob"` - a single `=` is for assignment, not comparison. – andrewsi Aug 09 '14 at 00:23

1 Answers1

1

if you are getting the value from URL(index.php?name=Bob) it has to be

$name = $_GET['name'];