Please see I already checked old threads but did not help.
Here is my code, seems ok but gives error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
code:
function getPnr()
{
$con = mysqli_connect('127.0.0.1', 'root', '', 'safari');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$pnr = mt_rand(1111111111, 99999999999);
$result = mysqli_query($con,"SELECT pnr from tbl_user where pnr = '".$pnr."'");
if(mysqli_num_rows($result)>0)
echo "emtpy";//getPnr();
else
echo $pnr;
}
what's wrong here?
UPDATED code:
function getPnr()
{
$con = mysqli_connect('127.0.0.1', 'root', '', 'safari');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$pnr = mt_rand(1111111111, 99999999999);
$result = mysqli_query($con,"SELECT user_pnr from tbl_user where user_pnr = '".$pnr."'") or die(mysqli_error($con);
if(mysqli_num_rows($result)>0)
echo "emtpy";//getPnr();
else
echo $pnr;
return; }
new error:
Parse error: syntax error, unexpected ';' in F:\wamp\www\safari\REST_APIs_for_RedBus\main.php on line 104