Presence list php and Pdo

Asked

Viewed 229 times

0

What I’m trying to do is that all people connected to the logged-in user in session appear with a checkbox so that I can put whether he was present or not and is not appearing there for me to put 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");
	}
?>

page of presence

                        <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 } ?>

  • What’s the matter?

  • does not appear the name of the people with checkbox that selected it as leader, I just edit because it had some visible errors but does not work yet...

1 answer

1


Try it like 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);
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.