-1

This is my code I am Assigning a value to PHP but Not able to get in PHP SESSION. Tried all possible way. Also, I tried to set SESSION from javascript not get values.

 var designation = $("#Designation").val();
              <?php $_SESSION['lclDesignation'] = "<script type='text/javascrip'>alert(desi);</script>"?>
6
  • 3
    Use ajax to send data from js to php Commented Oct 1, 2018 at 6:55
  • I am not sending any value, just I am setting session and accessing that set value in another page. Commented Oct 1, 2018 at 6:56
  • do you want to assign js code to a session? Commented Oct 1, 2018 at 6:57
  • YES, js value to session Commented Oct 1, 2018 at 6:57
  • You got a typo. Please see <script type='text/javascrip'>. Commented Oct 1, 2018 at 7:00

1 Answer 1

2

It's not possible to directly assign session value. using AJAX to assign the session value. Please review below code

var designation = $("#Designation").val();
$.ajax({
  url: "session.php",
   type: "POST",
   data : {'designation' : designation },
  success: function(html){

  }
});

Then create the session.php file paste the below code

session.php

session_start();

$_SESSION['lclDesignation']=$_POST['designation'];
Sign up to request clarification or add additional context in comments.

8 Comments

getting Undefined index: designation
Please implement & check updated answer
sessionStorage.setItem("lclDesiSession",$('#selDesignation1').val()); I am setting values in javascrip but not able access.
Yaa it's one of way. But it's not working some updated browser & IE. If you using ajax it's support all browser & mobile also.
your updated answer not working getting same notice as Undefined index: designation.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.