无论点击的个人资料如何,基于会员的网站都返回相同

时间:2017-04-15 16:03:33

标签: php mysql

我一直试图打开和关闭一段时间,但我有一个基于会员的网站,无论选择的个人资料如何都会返回同一个用户,我不确定是什么'继续

这是我的标题

<?php

//START SESSION
ob_start();
session_start();

include_once 'functions.php';

if(isset($_SESSION['email']))
{
    $email      = $_SESSION['email'];
    $loggedin  = TRUE;
    $userstr   = " $email";
} else {
    $loggedin = FALSE;
}

if($loggedin) {
    include_once "navIn.php";
} else {
    include_once "navOut.php";
}

这是我实际返回用户个人资料的功能。

function showProfile($email)
{
    if(file_exists("users/$row[0]/$row[0]pi.jpg"))
        echo "<img src='/users/$row[0]/$row[0]pi.jpg'>";
    else
        echo "<i id='user-img-dflt' class='fa fa-user' aria-hidden='true'></i><br>";

    $result = queryMysql("SELECT * FROM profiles");

    if(mysql_num_rows($result))
    {   
        $row = mysql_fetch_row($result);
        echo "Contact: $row[3]"; 
        echo "<h4>Statement</h4>";
        echo "<p>";
        echo stripcslashes($row[2]) . "<br clear='left' /><br/>";
        echo "</p>";
        echo "<h4>Work</h4>";
        echo "<div class='gallery row'>";

        //image1
        if(file_exists("users/$row[0]/work/$row[0]w1.jpg"))
            echo "<div class='col-md-2'>".
                 "<a href='/users/$row[0]/work/$row[0]w1.jpg'>" .
                 "<img class='thumbnail' src='/users/$row[0]/work/$row[0]w1.jpg'>" .
                 "</a>" .
                 "</div>";
            else 
                echo "<div class='col-md-2'></div>";

        //image2
        if(file_exists("users/$row[0]/work/$row[0]w2.jpg")) {
            echo "<div class='col-md-2'>".
                 "<a href='/users/$row[0]/work/$row[0]w2.jpg'>" .
                 "<img class='thumbnail' src='/users/$row[0]/work/$row[0]w2.jpg'>" .
                 "</a>" .
                 "</div>";
        } else {
            echo "<div class='col-md-2'></div>";
        }

        //image3
        if(file_exists("users/$row[0]/work/$row[0]w3.jpg")) {
            echo "<div class='col-md-2'>".
                 "<a href='/users/$row[0]/work/$row[0]w3.jpg'>" .
                 "<img class='thumbnail' src='/users/$row[0]/work/$row[0]w3.jpg'>" .
                 "</a>" .
                 "</div>";
        } else {
            echo "<div class='col-md-2'></div>";
        }

        //image4
        if(file_exists("users/$row[0]/work/$row[0]w4.jpg")) {
            echo "<div class='col-md-2'>".
                 "<a href='/users/$row[0]/work/$row[0]w4.jpg'>" .
                 "<img class='thumbnail' src='/users/$row[0]/work/$row[0]w4.jpg'>" .
                 "</a>" .
                 "</div>";
        } else {
            echo "<div class='col-md-2'></div>";
        }

        //image5
        if(file_exists("users/$row[0]/work/$row[0]w5.jpg")) {
            echo "<div class='col-md-2'>".
                 "<a href='/users/$row[0]/work/$row[0]w5.jpg'>" .
                 "<img class='thumbnail' src='/users/$row[0]/work/$row[0]w5.jpg'>" .
                 "</a>" .
                 "</div>";
        } else {
            echo "<div class='col-md-2'></div>";
        }

        //image6
        if(file_exists("users/$row[0]/work/$row[0]w6.jpg")) {
            echo "<div class='col-md-2'>".
                 "<a href='/users/$row[0]/work/$row[0]w6.jpg'>" .
                 "<img class='thumbnail' src='/users/$row[0]/work/$row[0]w6.jpg'>" .
                 "</a>" .
                 "</div>";
        } else {
            echo "<div class='col-md-2'></div>";
        }

        echo "</div>";
    }
}

最后,这是我的会员页面,显示会员并允许您点击个人资料。

<?php 
//members.php

include_once 'head.php';

echo "<div id='content' class='container'>";

if(isset($_GET['view']))
{
    $view = sanitizeString($_GET['view']);

    $result = queryMysql("SELECT * FROM members");
    $row = mysql_fetch_row($result);

    echo "<h3>$row[2] $row[3]</h3>";
    showProfile($view);
    echo "</div>";
    include_once 'footer.php';
    die();

}


$stuff = queryMysql("SELECT * FROM members");
$num    = mysql_num_rows($stuff);

echo "<h3>Members</h3>";
echo "<div class='row'>";

for ($j = 0; $j < $num; ++$j)
{
    $row = mysql_fetch_row($stuff);
    if($row[1] == $email) continue;

    if(file_exists("users/$row[0]/$row[0]pi.jpg")) {
        echo "<div class='col-md-4'><a href='?view=$row[0]'><img src='/users/$row[0]/$row[0]pi.jpg'/> <br>$row[2] $row[3]   </a></div>";
    }
    else {
        echo "<div class='col-md-4'><a href='?view=$row[0]'><i id='user-img-dflt' class='fa fa-user' aria-hidden='true'></i> <br>$row[2] $row[3]    </a></div>";
    }
}

echo "</div>";
echo "</div>";
?>

<?php include_once 'footer.php'; ?>

我的MySQL数据库非常简单,它有两个表:

成员[id,email,firstName,lastName,pass] 个人资料[id,声明,联系方式,网站]

当我点击其他个人资料时,视图ID是正确的,但个人资料仍然无关。

1 个答案:

答案 0 :(得分:0)

感谢发布的评论。 在我的showProfile函数中:

   $result = queryMysql("SELECT * FROM profiles WHERE id='$id'");

在我的会员页面中:

  $result = queryMysql("SELECT * FROM members WHERE id = '$view'");