Amoro Amoro - 2 months ago 9
MySQL Question

php sql value is empty redirect

I have a database table called recruiting with a field called

rct_app_uid
and
rct_app_id
, if there is no
rct_app_id
for the user I want the request to be redirected. If
rct_app_id
have value and is the same as
rct_app_uid
, the request wont be redirected.

$user_id = $_SESSION['uid'];

$sql = "SELECT * FROM recruiting WHERE rct_app_uid = $user_id";
$result = query($sql);

while(($row = mysqli_fetch_assoc($result))!=false){
echo $rct_app_uid = $row['rct_app_uid'];

if ($rct_app_uid >0){

return true;

} else {

redirect(ROOT_URI);

}
}

Answer

try this use mysqli_num_rows instead

$user_id = $_SESSION['uid'];

$sql = "SELECT * FROM recruiting WHERE rct_app_uid = $user_id";
$result = query($sql);


if (mysqli_num_rows($result) >0){

    return true;

} else {

  redirect(ROOT_URI);

}