使用JS将id发送到另一个php文件

i write below code for sending id to another php file

function selectCheckBox(k) {
    answer = confirm("Do you really want check?");
    if(answer == true) {
        var e = document.Check.elements.length;
        var cnt = 0;
        total = document.Check.elements[k].value;
        PostVar = "id=" + total;
        alert(PostVar);
        makePostRequest("check.php", PostVar);
    }
}

in this code i got PostVar value as id=121

in check.php code is as shown

require 'dbconnect.php';
$id=$_REQUEST['id'];
$query="update members set status_admin='Yes' where userid='$id'";
$result=mysql_query($query);

but results in the mysql table are not updated

please guide me

Few Suggestions For Debugging

  • Check the output of $_REQUEST using print_r($_REQUEST)
  • Or See output of your query using exit($query)
  • See if mysql returns any error mysql_query($query) or die(mysql_error())

And put this on top of your script to see any other errors from current page or included pages:

ini_set('display_errors', true);
error_reporting(E_ALL);

Can't you simply do makeGetRequest("check.php?id="+total); and get rid of the PostVar thing in some way? Your $_REQUEST will catch it nicely.

Also, careful the SQL injection! use $id=intval($_REQUEST['id']); instead.