1

this is my javascript code :

function  category(row){
    dataparam = "oper=delete&row="+row;
    $.ajax({
        type: "POST",
        url: "multiupload.php",
        data: dataparam,
        error:function() {
                alert("sorry")
        },
        success: function(html) {
            alert(html);
        }
    });
}       

and my php script :

$opers = (isset($_REQUEST['opers']) and $_REQUEST['opers'] != '' ) ? $_REQUEST['opers'] : '';
if($opers == "delete") {
        $row=$_REQUEST['row'];
        echo $row;
}

This is not working... I don't know what problem is. Please help me to get the $row variable in my php script.

krtek
  • 26,334
  • 5
  • 56
  • 84
sankars
  • 11
  • 1
  • 2
  • Possible duplicate of http://stackoverflow.com/questions/6130662/passing-javascript-variable-to-php-using-ajax/? – Liam May 26 '11 at 13:58

4 Answers4

1

In your dataparam variable you have "oper=delete&row="+row; and in the PHP code you test for $_REQUEST['opers']), since oper <> opers, the failure is perfectly normal, just add or remove the s somewhere.

krtek
  • 26,334
  • 5
  • 56
  • 84
1

It looks like you have this wrong, $_REQUEST['opers'] it should be $_REQUEST['oper']

$opers = (isset($_REQUEST['oper']) and $_REQUEST['oper'] != '' ) ? $_REQUEST['oper'] : '';  

if($opers == "delete") {
    $row=$_REQUEST['row'];
    echo $row;
}

I would also recommend that as you are expecting the values to come via URL you use the appropriate super global which is $_GET. There is a very small chance that a $_COOKIE could screw you over. If you use them and hapen to give it the value of 'oper'.

martynthewolf
  • 1,718
  • 2
  • 11
  • 22
0

You want $_REQUEST['opers'] while you pass oper. Notice the additional "s".

krtek
  • 26,334
  • 5
  • 56
  • 84
RRStoyanov
  • 1,162
  • 1
  • 13
  • 23
0
$opers = (isset($_REQUEST['oper']) and $_REQUEST['oper'] != '' ) ? $_REQUEST['oper'] : '';  
if($opers == "delete")
{
     $row=$_REQUEST['row'];
     echo $row;
}

Hopefully the problem is with the extra curly brackets. Check it. I have corrected the code. Let me know if it works. And there is an extra s in opers.

Sujit Agarwal
  • 12,348
  • 11
  • 48
  • 79