In this script im trying to check if a user exist. if it does, display if it doesnt display error message. The problem is I only get the error message so by Guessing the script is not returning anything correctly. Please kindly take a look. Thanks.
public function check_user($uid){
$sql = "SELECT * from users WHERE uid= :uid ";
$q = $this->db->prepare($sql);
$q->execute(array(':uid'=>$uid));
$result = $q->fetch(PDO::FETCH_ASSOC);
return $result;
}
profile.php
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
session_start();
include_once('php/classes/db_config.php');
include_once('php/classes/class.user.php');
$user1 = new User($con);
$is_loggedin = (isset($_SESSION['uid']));
$is_uid = (!empty($_GET['uid']) && is_numeric($_GET['uid']));
$def_uid = ($is_uid) ? $_GET['uid'] : $_SESSION['uid'];
$user_valid = ($is_uid == true) ? $user1->check_user($def_uid) : 1;
@$name_id = $_SESSION['user']['uid'];
$name = $_SESSION['user']['uname'];
$fullname = $_SESSION['user']['fullname'];
$bio = $_SESSION['user']['bio'];
$time = date("Y-m-d H:i:s");
if (isset($_POST['logout'])) {
session_destroy();
header('Location: index.php');
exit;
}
if (isset($_POST['area_sub'])) {
if (empty($_POST['area'])) {
echo "<script>alert('Empty area field.')</script>";
}else{
$uid = $_GET['uid'];
if ($uid == '' || $uid == 0) {
$uid = $name_id;
}
$user1->post($name_id, $uid, $name, $_POST['area'], $time);
}
}
if($is_loggedin){
$sql = "SELECT * FROM follow_req WHERE user_two_req= :user_two_req";
$query = $con->prepare($sql);
$query->execute(array( ':user_two_req' => $name_id));
$result = $query->fetchALL(PDO::FETCH_ASSOC);
}
?>
// If user is valid
if($user_valid == 1) {
// User is logged in user
if($def_uid == $name_id) {
include_once 'php/classes/profile_func.php';
}
include_once 'php/classes/user_info.php';
}else{?>
<h2>No Such User Exists</h2>
<h3>Please select a different user or <a href='index.php'>Login</a></h3>
<?php if($is_loggedin == true){ ?>
<h3>Go Back to <a href="profile.php?uid=<?php echo $name_id;?>">My Profile</a></h3>
<?php
}
} ?>