Renish Khunt
Renish Khunt

Reputation: 5824

jQuery send post request with php variable?

hello friends This is my code.

$.post("submit_investorform.php",{'flage':'firstOverviewsubmit','comname':comaname,'amoutwisr':amoutwisr,'user_id':<?php echo $value = isset($_GET['user_id']) ?  $_GET['user_id'] : ""; ?>},function(result){
    if(result.trim() == 'Insert'){
        $(".noterror").html("Record Insert Successfully");
        $(".noterror").show();
        return false;
    }else if(result.trim() == 'error'){
        $(".errordisplay").html("Something was Wrong Please Try Again");
        $(".errordisplay").show();
        return false;
    }else if(result.trim() == "update"){
        $(".noterror").html("Record Updated Successfully");
        $(".noterror").show();
        return false;
    }

});

i want to do the user_id is set then is send into post request otherwise it send blank. but jQuery return syntax error.

please help.

Upvotes: 0

Views: 85

Answers (1)

Nauphal
Nauphal

Reputation: 6192

try this

'user_id': '<?php echo $value = isset($_GET['user_id']) ?  $_GET['user_id'] : ""; ?>'

You need to wrap your PHP code within quotes to avoid syntax error, if the $_GET['user_id'] is not set.

Upvotes: 3

Related Questions