i am new to web development and i am trying to make a modal with data retrieved from data base depending on a selected value i used java script to get the selected value and to make the request
<script>
function getselectedc () {
var sel = document.getElementById('coursesids');
var sv = sel.options[sel.selectedIndex].value;
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.open("GET", "managerview.php?q="+sv, true);
xhttp.send();
}
</script>
when button is clicked modal should appear this is my html code for the buttton and modal
<button type="submit" onclick="getselectedc()" data-toggle="modal" data-target="#updateModal" class="btn btn-info btn-lg card" id="update" style="width:50%;" <?php echo $buttonenable;?> > <span class="glyphicon glyphicon-pencil"></span> Update</button>
<br> <br>
<!-- Modal -->
<div class="modal fade" id="updateModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="background-image:url(images/mb2.jpg);">
<div class="modal-header" style="padding:35px 50px; ">
<button type="button" class="close" data-dismiss="modal" >×</button>
<h1 style="color:#0e5c6d;"><span class="glyphicon glyphicon-pencil bold"></span> <strong >Update Course</strong></h1>
</div>
<div class="modal-body" style="padding:40px 50px; ">
<form role="form">
<div class="form-group" style="text-align:left;">
<label for="courseid">Course ID</label>
<input type="text" class="form-control" id="corseid" disabled placeholder=<?php echo $uid;?> >
</div>
<div class="form-group" style="text-align:left;">
<label for="noclasses">Number Of Classes</label>
<input type="number" class="form-control" id="noclasses" placeholder=<?php echo $nclasses;?> >
</div>
<button type="submit" class="btn btn-info btn-block"><span class="glyphicon glyphicon-ok"></span> Update</button>
</form>
</div>
</div>
</div>
</div>
my php code
<?php
$buttonenable="";
$nhrs=0;$nclasses=0;$price=0;$tcid=0;$sname="";$uid="";
$conn = mysqli_connect('localhost','root','','project');
if (mysqli_connect_error()) { die("Connection to database failed: " . mysqli_connect_error());}
$scid=$_GET["q"];
function populatecdata()
{
if($GLOBALS['scid']!="")
{ $sql="SELECT * FROM COURSES WHERE ID=".$GLOBALS['scid'];
echo $sql;
$result=mysqli_query($GLOBALS['conn'], $sql);
if (!$result) { die(mysqli_error($GLOBALS['conn'])); }
else {
$row = mysqli_fetch_assoc($result);
$GLOBALS['uid']='"'.$GLOBALS['scid'].'"';
$GLOBALS['nclasses']='"'.$row["NoOfClasses"].'"';
$GLOBALS['nhrs']='"'.$row["NoOfHours"].'"';
$GLOBALS['price']='"'.$row["Price"].'"';
$GLOBALS['tcid']='"'.$row["TrainerID"].'"';
$GLOBALS['sname']='"'.$row["Sportname"].'"';
}
}
}
populatecdata();
function options()
{
$x=0;
$sql ="SELECT ID FROM COURSES ";
$GLOBALS['result'] = mysqli_query($GLOBALS['conn'], $sql);
$r1="block";
if (!$GLOBALS['result']) { die(mysqli_error($GLOBALS['conn'])); }
$a=array();
$i=0;
if(mysqli_num_rows($GLOBALS['result']) > 0)
{
while($row = mysqli_fetch_assoc($GLOBALS['result']))
{
echo '<option value="'.$row["ID"].'">'.$row["ID"].'</option> '."\r\n";
}
$GLOBALS['buttonenable']="";
}
else {echo '<option value="0">no courses to show</option>';
$GLOBALS['buttonenable']="disabled";}
}
?>
i wrote all of this in one file named managerview.php the problem is when the modal appear data in it isn't correct (not the correct values from database) any help would be appreciatedthanks in advance sorry for the long post but i was only trying to make everything clear