php and pdo presence list

0

What I'm trying to do is that all the people connected to the user logged in to the session with a checkbox so I can put in if he was present or not and is not showing up there to put up presence ...

check.php

<?php
require_once("db.php");
function check_input($r){
	$r=trim($r);
	$r=strip_tags($r);
	$r=stripslashes($r);
	return $r;
	}

if (isset($_POST['uname'],$_POST['pwd'])){	
	$u=check_input($_POST['uname']);
	$p=md5(check_input($_POST['pwd']));
	try{
	$db=get_db();
	$stmt=$db->prepare("SELECT * FROM membros WHERE usuario=? && senha=?");
	$stmt->execute(array($u,$p));
	$r=$stmt->fetch(PDO::FETCH_ASSOC);
	if($r){
		session_start();
		$level=$r['level'];
		$_SESSION['usuario'] = $r['usuario'];
		$_SESSION['nome'] = $r['nome'];
	    $_SESSION['status'] = $r['status'];
	    $_SESSION['foto'] = $r['foto'];
		$_SESSION['level'] = $level;
		if ($level==0){
			header("Location: ../lider/");
			}
		else if($level==1){
			header("Location: ../pastor/");
			}
		}
	else{
		header("Location: ../login.php?err=1");
		}
	}
	catch(PDOException $e){
		die("Database error: ".$e->getMessage());
	}
}
else{
	header("Location:index.php");
	}
?>

presence page

                        <div class="form-group">
                          <label for="checkbox">Lista de Presença</label>
                          
                  <?php
                                    require_once("../cfg/db.php");
                                    $db=get_db();
                                    $stmt = $db-> prepare('SELECT lider,nome FROM membros WHERE lider = $_SESSION['nome']; ORDER BY nome');
                                    $stmt-> execute();
                                    $result = $stmt-> fetchAll(PDO::FETCH_ASSOC);
                                   //  print_r($result);
                                    ?>
                  <?php foreach( $result as $row ) { ?> 
               <div class="checkbox-inline1">
                  <label>
                        <input class="minimal" type="checkbox" name="presenca[]" value="<?php echo $row[0]['nome'];?>">  <?php echo $row['nome'];?> 
                  </label>
            </div>                
                  <?php } ?>
    
asked by anonymous 24.01.2018 / 17:46

1 answer

1

Try this:

<?php
    require_once("../cfg/db.php");
    $db=get_db();
    $nome = $_SESSION['nome'];
    $stmt = $db-> prepare("SELECT lider, nome FROM membros WHERE lider = '$nome' ORDER BY nome");
    $stmt-> execute();
    $result = $stmt-> fetchAll(PDO::FETCH_ASSOC);
    //  print_r($result);
?>
    
24.01.2018 / 18:21