hi i am new to php and javascript. i have a problem. i wanted to obtain a value from javascript function and pass it on to php and use that value for a query. here's the code:
<?php
$link=mysqli_connect("localhost","root","", "personinfo") or die("Error " .mysqli_error($link));
?>
<body>
<div id="qBox">
<p>Name: </p>
<select id="sel">
<option value="1">Person1</option>
<option value="2">Person2</option>
<option value="3">Person3</option>
</select>
<button onclick="myFunction()">Submit</button>
</div>
<script>
function myFunction(){
var x = document.getElementById("sel").value;
}
</script>
<?php
$did=x;
$sql="SELECT * FROM personinfo where id=$did limit 1" or die("Error in the consult.." . mysqli_error($link));
$aResult=mysqli_query($link, $sql);
while($rows = mysqli_fetch_array($aResult))
{
$id = $rows['ID'];
$pid = $rows['personID'];
$fname = $rows['firstName'];
$lname = $rows['lastName'];
$department = $rows['department'];
$type = $rows['fType'];
?>
<div id="combi">
<div id="tag">
<p id="pColor">ID</p>
<p id="pColor">FIRST NAME</p>
<p id="pColor">LAST NAME</p>
<p id="pColor">DEPARTMENT</p>
<p id="pColor">TYPE</p>
</div>
<div id="content">
<b><?php echo $pid;?><?php echo $id;?></b><br />
<b><?php echo $fname;?></b><br />
<b><?php echo $lname;?></b><br />
<b><?php echo $department;?></b><br />
<b><?php echo $type;?></b>
</div>
</div>
<?php }
?>
</body>
if there's a way to do that it will be much appreciated, if not, what do i need to do to make this work? i hope you could help. thanks.