Click here to Skip to main content
14,691,000 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello folks

Hope you're fine and protecting yourself from the terrible illness worldwide.

I got a datatable containing a "Details" button which should open a modal. I already succeed in getting the Id of a corresponding row into the modal, which I display into a text-field on an input tag.
I wish to get the value of the input tag(the correspmonding row Id) into a PHP variable inorder to perform a query in the DB. The value of the input tag in question is gotten from Javascript.
After researches, I found out that using AJAX was the best way to achieve this, but the code I implemented throws an error.

The error says:
Notice: Undefined index: sessionIdToPost in C:\wamp64\www\project apache test\HTML\Sessions_infos.php on line 186

Thanks in advance for your kind help!

What I have tried:

Here is what've tried
HTML code:
<td><button type="button" class="btn btn-info sessionDetails" session-id="<?php echo $row['sessionid']; ?>"
                  style="font-family:comic sans Ms ; font-size: 15px; font-weight: lighter;background-color: #3cc1fc;
                  border-radius: 2px;">Détails </button></td>

Modal content:
The input tag in which I display the Id in the modal
<input type="text" id="sessionId" value="">

PHP Code to retrieve the value of the input tag from the javascript side
$_SESSION['sessionId'] = "";
$_SESSION['sessionId'] = $_POST['sessionIdToPost'];

JS Code:
$(document).ready(function() {
  // when the button will be clicked the function will be called
      //removing previous value
      //set modal's Id to corresponding Id from table


    // This sends the value of the input to the PHP server
      var sessionId_data = $(this).val();

      //Send data to server
      $.post("/Sessions_infos.php", {"sessionIdToPost": sessionId_data});

Richard MacCutchan 30-Mar-20 3:42am
You have not defined sessionIdToPost anywhere in your HTML.
Nice Kloe 30-Mar-20 6:09am
Thanks for your response, Richard. But I'm somehow confused. Since the value of the
should come from the JavaScript side and be posted to the $_POST['sessionToPostId'], how should I define it? Could you be more explicit, please?
Nice Kloe 1-Apr-20 16:50pm
Hello everyone. Please, could I have some more guides on how to solve my problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900