I got this if statement that executes this function
if table is not empty update the required information else execute the insert query. but the problem is i cannot get into the insert part instead I'm being returned to the update query even though the table is empty.
Below is my query which checks if the information is already in the table.
$checkquery = "SELECT user_type_id , user_school_verification_id , resource_no ,resource_title , SUM(quantity) as Total_Quantity FROM tbl_borrow_issuance WHERE user_type_id = ? AND user_school_verification_id = ? AND resource_no = ?";
$stmt1 = $mysqlconnection->prepare($checkquery);
$stmt1->bind_param("sss",$getusertype, $getstudentno , $getresourceno );
$stmt1->execute();
$stmt1->store_result();
$stmt1->bind_result($user_type_id, $user_school_verification_id, $resource_no, $resource_title, $Total_Quantity );
And Here is my if statement
if($stmt1->num_rows > 0){
while ($stmt2->fetch())
{
$user_type_id = $user_type_id;
$borrow_count = $borrow_count;
$Total_Quantity = $Total_Quantity;
$resource_no = $resource_no;
// $gettotalfinal = $getresourcequantity +
if ($getusertype == $user_type_id && $getresourcequantity <= $borrow_count)
{
if ($getusertype == $user_type_id && $Total_Quantity == $borrow_count){
echo "ERRORMAX";
}
else
{
$add_quantity = "UPDATE tbl_borrow_issuance SET quantity = quantity + ? WHERE resource_no = ? ";
$stmt3 = $mysqlconnection->prepare($add_quantity);
$stmt3->bind_param("ss", $getresourcequantity, $resource_no);
if ($stmt3->execute()) {
echo "SUCCESS";
}else
{
echo "ERROR";
}
}
}
else
{
echo "ERRORUSER";
}
}
}
else
{
$query = "INSERT INTO tbl_borrow_issuance (user_type_id , user_school_verification_id, resource_no , resource_title , quantity ) VALUES (? , ? , ? ,? , ?)";
$stmt = $mysqlconnection->prepare($query);
$stmt->bind_param("sssss",$getusertype, $getstudentno, $getresourceno , $getresourcetitle ,$getresourcequantity);
if ($stmt->execute())
{
echo "SUCCESS1";
}
else
{
echo "ERROR";
}
}