The MySQLi Stored Procedures documentation gives some specific guidance on calling stored procedures with MySQLi:
Stored procedures can return result sets. Result sets returned from a stored procedure cannot be fetched correctly using mysqli_query(). The mysqli_query() function combines statement execution and fetching the first result set into a buffered result set, if any. However, there are additional stored procedure result sets hidden from the user which cause mysqli_query() to fail returning the user expected result sets.
Result sets returned from a stored procedure are fetched using mysqli_real_query() or mysqli_multi_query(). Both functions allow fetching any number of result sets returned by a statement, such as CALL. Failing to fetch all result sets returned by a stored procedure causes an error.
Given this information, it's better to use the mysqli_real_query
function to retrieve the results that you need. Use this code, instead:
$ret=mysqli_real_query($connection,"call FP_USER_EXISTS('$emailid')");
if($ret==1)
{
echo "Error: " . mysqli_error();
}
else
{
if ($row = mysqli_fetch_array($result)) {
if ($row[0]) {
echo 'Inserted successfully';
} else {
echo "User already exits";
}
} else {
echo "No result returned";
}
}
This code assumes that the stored procedure returns TRUE
if a new record is inserted, or FALSE
if it is not. If this is not the case (because these details are not present in the question), you will have to adjust accordingly. The additional error handling is used to make sure that the statement itself was successfully executed, and that at least one result row was returned.