dongmei1988 2014-11-20 15:51
浏览 68
已采纳

从DB返回值。 PHP

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
                }
            } ?>
  • 写回答

1条回答 默认 最新

  • duanjiu4498 2014-11-20 16:04
    关注

    Fixed it.

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

    changed it to:

    --> if($user_valid == true) {
                // 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
                }
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上