I am trying to get values from table the problem I am facing is that regardless of what the input is it gives me the result of both rows. I want to match the input ID with the ID in the table. This is the code I am trying to useImage of the table is attached the file name is linked with the javascript file where I have a click function and this javascript(global.js) file is linked with another file having text box. My main file code is below
<!DOCTYPE html>
<html>
<head>
<title>products</title>
</head>
<body>
Item:
<input type="text" required id="item">
<input type="submit" id="item-submit" value="Grab">
<div id="item-data"></div>
<script src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="js/global.js"></script>
</body>
</html>
global.js file code
$(document).ready(function(){
$('input#item-submit').click(function(){
var item = $('input#item').val();
if ($.trim(item) != ''){
$.post('ajax/name.php',{item:name}, function(data){
$('div#item-data').text(data);
});
}
})
});
name.php file code is below
require '../db/connect.php';
$sql = "SELECT BarcodeID, shirts, price FROM clothes WHERE BarcodeID = ($_POST['name']) ";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo " " . $row["BarcodeID"]. " shirt color: " . $row["shirts"]. " price: " . $row["price"];
}
mysqli_close($con);