参数数据无效时,API调用不返回错误

时间:2018-01-13 13:40:11

标签: php

我目前正在尝试PHP GET请求,但坚持这一点。 请记住,我还没有真正尝试过这个。 所以现在对我而言,

要点......

如果用户未指定,我正在尝试返回无效的参数消息 以下参数之一

一直在修补这个问题, 但无法真正弄明白。

  

?param = first或?param = second

但它返回它仍然返回有效的参数消息。 有什么建议吗? 我会把我的代码放在下面!

<?php

$param = $_GET['param'];

if (empty($_GET['param']))
  {
    print('<h2>Parameter param is not set!<h2>');
    print '<br>';
    print('<h5><font color="red">Proper usage: http://localhost/zoek.php/?param=first</font></h5>'); //first
    print('<h5><font color="red">Or second http://localhost/zoek.php/?param=second</font></h5>'); //second
    die();
  }


 ?>


<?php


if ($param == 'first')
  {
    print('Do something when url = http://localhost/zoek.php/?focus=first');
    //do more stuff
  }

else if ($param = 'second')
  {
    print('Do something when url = http://localhost/zoek.php/?focus=second');
    //do more stuff.
  }


//attempt to return error message when parameter $param is not first or second
else
  {
    print('The by you specified argument '. $_GET['param'] .' is invalid.');
    die();
  }


?>

1 个答案:

答案 0 :(得分:0)

问题在于这一行:

else if ($param = 'second')

应该是==而不是=