Delimiter $
CREATE FUNCTION FP_USER_EXISTS(xemailid VARCHAR(50)) RETURNS int(11)
BEGIN
SET @User_exists = 0;
SELECT COUNT(*) INTO @found FROM login WHERE emailid = xemailid;
IF @found > 0 THEN
SET @User_exists = 1;
END IF;
RETURN @User_exists;
END $$
function calling in mysql
@return=FP_USER_EXISTS('testing@test.com')
select @return here it shows return value 0 or 1 but in php it is not returing value
$ret=mysqli_query($connection,"select FP_USER_EXISTS('$emailid')");
if($ret==1)
{
echo "User already exits";
}
else
{
echo 'Inserted successfully';
}
every time it is showing one value based on condition
Thanks
how to get mysql function return value in variable using php
Moderator: General Moderators
Re: how to get mysql function return value in variable using
What you're doing boils down to just a simple SELECT query. So you have to work with it the same way you would work with other SELECT queries: execute and fetch a row.
You should also be using prepared statements because of that email address.
Code: Select all
$ret=mysqli_query($connection,"select FP_USER_EXISTS('$emailid')");
list($user_exists) = mysqli_fetch_row($ret);
if($user_exists == 1)
{