first time here. I'm struggling to get this PHP function to work, and after 5 hours it's driving me insane.
I have this function:
// DOES THE USER HAVE ACCESS?
function access_la_page($id) {
include('DB_db.php');
/// GENERATE SQL
$sql = "SELECT parent FROM la_pages WHERE id = $id";
// PREPARE THE STATEMENT
$result = mysqli_query($conn, $sql);
if($result === false) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
echo "FAIL" . $conn->error; exit();
}
$row = mysqli_fetch_array($result);
// CHECK PERMISSIONS DATABASE TO SEE IF USER HAS ACCSS HIGHER UP THE CHAIN
$sql2 = "SELECT * FROM la_pages_permissions WHERE la_page_id = $id AND user_id = " . $_SESSION['user_id'];
$result2 = mysqli_query($conn, $sql2);
if($result2 === false) {
trigger_error('Wrong SQL: ' . $sql2 . ' Error: ' . $conn->error, E_USER_ERROR);
echo "FAIL" . $conn->error; exit();
}
if(mysqli_num_rows($result2) > 0){
$value = TRUE;
return $value;
}elseif($row['parent']!==$id&&$row['parent']&&!isset($value)) {
access_la_page($row['parent']); // CHECK DB RECURSIVELY TO SEE IF USE HAS PERMISSION HIGHER UP THE CHAIN
}
}
I then call this function:
if(access_la_page($_SESSION['la_page_id'])==TRUE){
echo "Success";
}else{
echo "Fail";
}
Now... If the function hits TRUE on the first instance it will in fact return TRUE to my page, success! But if it loops it does not return TRUE. It returns nothing.
But, when I echo from the statement I can see that the function is performing as it should, and when I echo $value, it shows TRUE and the function ceases - which is what should happen. But the function does not return TRUE.
Does that make sense, is this not working because I'm looping through the function?
EDIT - Excuse my ignorance. I had TRUE in quotes, I've modified that now but it doesn't work still