I'm using post method to get the id but everytime tells me Undefined variable $id here is my code:
<?php
require 'DBConnection.php';
$code='';
if(isset($_POST["ID"])){
if($_POST(["ID"]) != ''){
$id = $_POST['ID'];
$get_c = $pdo->prepare("SELECT * FROM all_menu WHERE `ID` = '".$id."'");
$get_c->execute();
while ($row = $get_c->fetch()) {
$code .= $row['item_code'];
}
echo $code;
}
}
Edit: I'm using this code to select from dropdown options to get the ID of the value in dropdown for example I have three options in my select dropdown let's say the first one is "Pepsi" when I select "Pepsi" I need to put its ID in an input I'm using PHP and Ajax in this code.
Here is my Ajax code:
<script>
$(document).ready(function(){
$('#itemname').change(function(){
var code = $(this).val();
$.ajax({
type: 'POST',
url: 'pages/GetCode.php',
data:{code:code},
success: function(data){
document.getElementById("itemcode").value = data;
},
error: function (jqXHR, textStatus, errorThrown){
alert(errorThrown);
}
});
});
});
</script>