PHP isset函数不起作用

时间:2016-08-08 14:58:14

标签: php forms function mysqli isset

如果有人知道如何使其工作,则不会触发该功能

if ($logged_in_bool == "true") {
    echo "<form action='page-settings.php?name=".$name."' method='POST'>
        <input type='button' name='delete_page' value='Delete Page'>
        </form>
";
} else {


}

$clicked_delete = @$_POST['delete_page'];

if (isset($clicked_delete)) {
    delete_page();
} else {
}

function delete_page() {
    echo "Page deleted";
}


?>

如果有人知道如何使其正常工作,则不触发该功能

3 个答案:

答案 0 :(得分:0)

第3行type=button应该被type=submit替换,因为type=button不提交表单,除非您在没有提交POST表单时使用一些JavaScript来执行此操作$ _POST变量中没有任何内容,因此未设置$ _POST ['delete_page]。请参阅下面的修改代码:

// $name is probably the name of the page to be deleted, not mentioned in the question
$name = 'example';
// $logged_in_bool comes from somewhere else not mentioned in this problem
$logged_in_bool = true;
if ($logged_in_bool) 
{
    echo "<form action='page-settings.php?name=" . $name . "' method='POST'>
              <!-- Input type changed from button to submit -->
              <input type='submit' name='delete_page' value='Delete Page'>
          </form>";
}
// If the $_POST['delete_age'] from the form is available, delete the page
if (isset($_POST['delete_page'])) {
    delete_page();
} else { }

function delete_page() {
    echo "Page deleted";
}

答案 1 :(得分:0)

为什么你不使用type =&#39;提交&#39; ?那么,如果您尝试将类型按钮更改为类型提交,如下所示:

<input type='button' name='delete_page' value='Delete Page'>

更改为:

<input type='submit' name='delete_page' value='Delete Page'>

答案 2 :(得分:0)

由于我的预告片已经告诉你该做什么,我想告诉你,isset语句不起作用的原因是变量$ clicked_delete实际上是设置的,因为你声明它并给它$ _POST的值[ 'delete_page']。所以你要么使用

PUT assets/_mapping/assets_type
{
  "properties": {
    "General": {
      "properties": {
        "deviceLocation": {  
          "type": "geo_point"
        }
      }
    },
  }
}

或者你可以使用空函数(我推荐第一个解决方案)

$clicked_deleted = (isset($_POST['deleted_page'])) ? true : false;

if ($clicked_deleted) { /* ... */ }