有三个按钮,$_GET['type']分别是1,2和3.代码如下所示,那个update userbbs的sql语句会报错:
<?php 
    date_default_timezone_set('Asia/Shanghai');
require_once("../../config.php");
    require_once("../base/connect.php");
require_once("../function/function.php");
if ($_GET['type']==1)
{
    $username=check_input($_POST['username']);
    $comment=check_input($_POST['bbs_content']);
    $title=check_input($_POST['title']);
if(stripos($comment,'Reply'))
{
$reply_time=date("Y-m-d H:i:s");
$sql="update userbbs set flag=1,reply='$comment',reply_time='$reply_time' where ID=$huifuid";
$result=@mysql_query($sql);
 if ($result)
        {
        echo "ok";
            }
 else
        {
       echo $ID;
        }
}
else
{
        if(!$title)
        {
        $title=" 无";
        }
        if($username and $comment)
    {
            $userip=myip2long($_POST['userip']);
            $bbstime=date("Y-m-d H:i:s");
            $sql="insert into userbbs (username,IP,title,comment,comment_time) values('$username',$userip,'$title','$comment','$bbstime')";
                $result=@mysql_query($sql);
            if ($result)
            {
            echo "ok";
                }
            else
            {
           echo mysql_error();
            }
        }
    else
    {
    echo "empty";
    }
    }
}//$_GET['type']==1
else if($_GET['type']==2)
{
$ID=check_input($_GET['ID']);
$sql="delete from userbbs where ID =$ID";
 $result=@mysql_query($sql);
    if ($result)
    {
    echo "ok";
        }
    else
    {
    echo mysql_error();
    }
}
else if($_GET['type']==3)
{
$ID=check_input($_GET['ID']);
$huifuid=$ID;
}
?>
如何让点击按钮3(即$_GET['type']==3)时获得的数据$ID传送到变量$huifuid中,并能在$_GET['type']==1时执行的sql语句中顺利用到这个变量的值呢?

解决方案 »

  1.   

    应该是AJAX吧。你把AJAX的代码贴出来。
      

  2.   

    $('#button_submitID').click(function()
    {
    $.ajax
    ({
          type:'POST',
        url:'php/action/bg_editbbs.php?type=1',
                           data:$("form").serialize(),//序列化表单里所有的内容
                             success: function(data)
     {
                                 if (data=='ok')
     {
            alert("留言成功!");
        window.location.reload();
     }
    else if(data=='empty')
    {
    alert("请输入昵称和留言内容!");
    }
    else
     {
        alert(data);
     }
          }
    });
    });
    $('.del_button').click(function(){
        var id=$(this).attr("id");
    $.ajax
    ({
          type:'GET',
        url:'php/action/bg_editbbs.php?type=2&ID='+id,
                             success: function(data)
     {
                                 if (data=='ok')
     {
            alert("删除成功!");
            window.location.reload();
     }
     else
     {
        alert("出现错误,请重试!\n"+data);
     }
          }
    });
    });
    $('.huifu').click(function(){
     var id=$(this).attr("id");
    document.getElementById('input_bbs').value=' Reply:'+' ';
    $('#input_bbs').focus();
    $.ajax
    ({
          type:'GET',
        url:'php/action/bg_editbbs.php?type=3&ID='+id,
     success:function(data)
     {
     alert(data);
    }
          });

    });