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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化