0

I'm trying to send to a php page a value with the POST method but it doesn't work.

The javascript code is:

 function op_infoMeeting(id_met){
            $('#modalInfoMeeting').find('.modal-title').text("Info 
Meeting");
            $('#modalInfoMeeting').modal('show');
    var xhttp = new XMLHttpRequest();
    xhttp.open("POST", "infoMet.php", true);
    xhttp.setRequestHeader("Content-type", "application/x-www-form- 
urlencoded");
    xhttp.send(id_met);
    return true;

  }

The code of infoMet.php is:

 <?php


$idMet=$_POST["id_met"];

 echo $idMet;
include "DB.php";

$query=mysqli_query($connessione,"select title,date,place from meeting where 
 meeting_id=".$idMet."");


 while($row=mysqli_fetch_array($query,MYSQLI_ASSOC))
   {

    echo "Staff Name:" . "<input type='text' value='" . $row['name'] . "'>";
    echo "</br>";
    echo "Contact No.:" . "<input type='text' value='" . $row['title'] . 
"'>";
 }
?>

It gives me this error:

Undefined index: id_met in infoMet.php on line 4

MrCaptain Alex
  • 137
  • 1
  • 11
  • You need to provide a [mcve]. You never show us the value of `id_met` (although it seems it is not the x-www-form- urlencoded expression of id_met with a value. – Quentin Jun 06 '18 at 20:59
  • **Danger**: You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that you need to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Jun 06 '18 at 20:59
  • id_met value is 1. I saw it with a innerHTML and it is passed correctly. – MrCaptain Alex Jun 06 '18 at 21:14
  • `1` is not x-www-form-urlencoded. You should read up on what that format looks like. – Quentin Jun 06 '18 at 21:24
  • Duplicate: https://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request – Quentin Jun 06 '18 at 21:25
  • I still do not understand where the error is. – MrCaptain Alex Jun 07 '18 at 09:08

0 Answers0