在mysql表中需要弹出窗口

时间:2013-07-23 14:32:09

标签: php mysql

我有一个简单的网站,由php和mysql代码编写。我在我的sql表查询页面上有一个检测按钮,下面给出的代码是为这个函数编写的,但我的问题是当点击检测链接时我需要一个弹出窗口。我已经厌倦了在我创建的代码中设置代码,但我无法。请帮助我解决这个问题。

    <?php $sezione="home_admin"; if(isset($_POST['messaggio']))
$messaggio=$_POST['messaggio']; 
include("control_admin..php");
 $canc_id=$_GET['canc_id']; 
$idcorsocanc=$_POST['idcorsocanc']; 
$action=$_REQUEST['action'];?>
        <?php 
        /*echo "permessi".$permessi;
        echo "<br>id".$id_nome;*/

        if($action=='canc'){?>
            <h1>are you sure want to delect the course?</h1>
        <form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc1" style="float: left; margin-left:25px;">
        <input type="hidden" name="idcorsocanc" value="<?=$canc_id?>">
        <input type="hidden" name="action" value="">
        <input type="submit" name="ok" value="Si,cancella" class="puls_invia">
        </form>

        <form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc2" style="float: left; margin-left:25px;">
        <input type="hidden" name="action" value="">
        <input type="submit" name="ok" value="NO" class="puls_invia">
        </form>
        <?php
        }

好的,我想更新我的问题,因为我按照一个答案,这里的代码是 -

<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
    $('#ok').click(function(){
        if(confirm('Are you sure ?')){
            $('#form').submit();
        }else{
            return false;       
        }
    });
});

</script>
</head>
<body>
<?php
if(isset($_POST['action'])){
    if($_POST['action'] == 'deleted'){
        //the form has been sent, do something
    }
}else{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="form">
    <input type="button" id="ok" name="ok" value="Delete">
    <input type="hidden" id="action" name="action" value="deleted">
</form>
<? } ?>
</body>
</html>

但直到现在我的问题是我alreday有链接名称delect和如果我点击该链接我看到另一个删除按钮因为现在我使用下面的代码我刚刚更新然后如果我点击那里我看到弹出窗口但是如果我点击确定该课程不是删除因为我猜想有些东西丢失了。

我的实际需要是我alreday有delect链接,我需要一些东西,如果我点击我看到一个opoup window.just这是我的需要。

2 个答案:

答案 0 :(得分:0)

您需要一个客户端脚本来管理它。我在jQuery中推荐一些东西。

<script type="text/javascript">

$(document).ready(function(){

$(".myButton").click(triggerPopup); 

})

function triggerPopup(){
//do popup stuff 
}

</script>

通过谷歌搜索可以找到更多细节的例子。像这样http://istockphp.com/jquery/creating-popup-div-with-jquery/

答案 1 :(得分:0)

你应该在javascript中执行此操作。特别是使用jquery库

这应该是这样的:

<?php 
include("control_admin.php");
$sezione = "home_admin"; 
$canc_id = $_GET['canc_id']; //i'm gessing this is the ID to delete ?
?>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
    $('#ok').click(function(){
        if(confirm('Are you sure ?')){
            $('#form').submit();
        }else{
            return false;       
        }
    });
});

</script>
</head>
<body>
<?
if(isset($_POST['action'])){
    if($_POST['action'] == 'deleted'){
        $id = $_POST['id'];
        $sql = "delete from table_name where column_id = ".$id;
        mysql_query($sql);
        echo $canc_id . ' has been deleted!';
    }
}else{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="form">
    <input type="button" id="ok" name="ok" value="Delete">
    <input type="hidden" id="action" name="action" value="deleted">
    <input type="hidden" id="id" name="id" value="<?=$canc_id?>">
</form>
<? } ?>
</body>
</html>