用PHP确认框?

时间:2016-06-06 13:56:47

标签: javascript php dialog

我正在开发一个Web应用程序,我想在按下停用按钮时从用户那里得到答案(是或否)。我想问他是否要停用该帐户。我使用PHP在停用时将活动状态设置为= 1,将0设置为激活。

我想得到结果并在PHP中验证查询是否运行。

如果有人帮助我,我将不胜感激,谢谢。这是代码:

 if(isset($_POST['desativar']))
{

  $login = $_SESSION['login'];


   mysqli_query($conexao,"UPDATE usuarios SET ativo_usuario = 1 WHERE login_usuario='$login'");

}

5 个答案:

答案 0 :(得分:0)

**JS**

    <script type="text/javascript">
    function confirmDesactiv()
    {
       var flag = confirm("Are you sure ?");
       if(flag)
            window.open("yourphp.php?id=" + 1);
        else
            window.open("yourphp.php?id=" + 0);
    }

</script>
**HTML**    



    <form method="POST" action="">
    <button type="submit" onclick="confirmDesactiv()">Desactiv my account</button>
    </form>



**PHP**   

<?php
echo $_GET['id'];
if(isset($_GET['id']) && $_GET['id'])
{
    //your update query will come here
}
?>                                                                                            

答案 1 :(得分:0)

试一试。

function confirm_delete(){
    if(confirm("Are you sure you want to delete this..?") === true){
        return true;
    }else{
        return false;
   }
 }

 <input type="button" Onclick="confirm_delete()">

答案 2 :(得分:0)

您可以使用 onsubmit 属性。

示例

collapseState = columns[i].children[j].children.getElementsByTagName('blahblah');
function confirmDesactiv()
{
   if(confirm("Are you sure ?"))
     return true;
  
  return false;
}

答案 3 :(得分:0)

您可以使用PHP制作类似确认框的内容。下面是一个简单的代码,向您展示如何:

<?php
session_start();

if (isset($_POST['submit'])) {
    $_SESSION['postdata'] = $_POST;
    header("Location: ".$_SERVER['PHP_SELF']);
    exit;
} else if (isset($_POST['confirm']) && $_POST['confirm'] == 'yes') {
    // Do stuff that should only be done after confirming
} elseif (isset($_POST['confirm']) && $_POST['confirm'] == 'no') {
    // Cancelled, redirect back to page
    header("Location: ".$_SERVER['PHP_SELF']);
    exit;
}
?>

<?php if (isset($_SESSION['postdata']) && !isset($_POST['confirm'])): ?>
    <form method="POST" action="<?= $_SERVER['PHP_SELF']; ?>">
        Are you sure you want to do this?<br />
        <input type="submit" name="confirm" value="yes">
        <input type="submit" name="confirm" value="no">
    </form>
<?php else: ?>
    <!-- Your form here -->
<?php endif; ?>

答案 4 :(得分:0)

如果您不想使用AJAX,并假设您的页面名为index.php:

<?
   $deactivateStatusDisplay = "display: none"; // Initially, do not display a status.
   $deactivateStatusMsg = ""; //Status message is initialized as blank.
   $queryRan = false; // Just a flag to know if the user clicked deactivation link.

   if( 1 === $_GET['deactivate'] ){
      $deactivateStatusDisplay = "display: block";
      $deactivateStatusMsg = "Your account will be deactivated.";
      $queryRan = true;
   }
?>

<!DOCTYPE html >
<html>
     <head>
       <!-- ALL YOUR METADATA -->
     </head>
     <body>
         <div>Do you want to deactivate your account?</div>
         <a href="index.php?deactivate=1">DEACTIVATE</a>
         <div id="status" style="<? echo $deactivateStatusDisplay ?>"><? echo $deactivateStatusMsg ?></div>
     </body>
</html>