Sorting data from a table, assigning a variable, and then calling from another file
I have a table inside my larger database that stores the quantities and I can run a query to call those values (pretty simple), but when I paste the following code into my PHP file and call it from another file, I always get mistake:
PHP fatal error: calling member function fetch_assoc () on non-object
$use = $conn->query("select Quant_Limit from Follett_qty where ISBN = $isbn");
$rowUser = $use->fetch_assoc();
$follettLimit = $rowUser['Quant_Limit'];
if ($follettLimit==null){
$follettLimit= 25;
}else {
$follettLimit= $follettLimit;
}
source to share
Your request is incorrect, therefore
$conn->query("select Quant_Limit from Follett_qty where ISBN = $isbn");
returns false
. false
is not an object, so you cannot call it fetch_assoc()
.
You can understand why your request is incorrect in your server's error log. Maybe $ isbn is not a numeric field, in which case you need to change that to where ISBN = '$isbn'"
.
source to share
Suggest using bug reporting. Also invite you to check the query result. You can try something like this
$use = $conn->query("select Quant_Limit from Follett_qty where ISBN = '$isbn'")
or die($conn->error);
$rowUser = $use->fetch_assoc();
$follettLimit = isset($rowUser['Quant_Limit']) ? $rowUser['Quant_Limit'] : null;
source to share