I am trying to query MySQL to see if a product number exists in the table. I am using the .get() JQuery method, but unable to get a proper return value.
Essentially, I want to to see if 'partNumber' is in the db, and add it to the HTML if so. The way I understand it from various sites is that the parameter of the success function in .get() is where the return value from the PHP is stored, so I would expect 'found' to hold
mysql_query("SELECT Part Number FROM Part List WHERE Part Number = $part_number");
This has not been the case, 'found' actually holds the entire "widget.php" page. I am not sure if my error lies on the server or client side of things.
jQuery:
$(document).ready(function(){
var partNumber = buildPartNumber();
$.get("widget.php", partNumber, function(found) {
if(found) {
$('#partNumber').html(partNumber);
}
else {
$('#partNumber').html("Sorry, we do not carry a product matching these specifications.")
}
});
}
PHP:
<?php
$hostname="hhh";
$database="ddd";
$username="uuu";
$password="ppp";
$link = mysql_connect($hostname, $username, $password);
mysql_select_db($database, $link);
$part_number = $_GET["partNumber"];
return mysql_query("SELECT Part Number FROM Part List WHERE Part Number = $part_number");
mysql_close($link);
?>