MySQL如何从行中相同的不同列查询数据?

时间:2015-03-07 09:45:23

标签: php mysql

这是图片:http://oi60.tinypic.com/118iq7r.jpg

我有一个类似于上表所示的数据库结构。但是,我有额外的登录时间列。我想从列中获取数据并将其显示在页面上。

ID | txtName | txtEmail        | txtPasswd
-------------------------------------------
1  | Ahmet   | ahmet@gmail.com | 123123
2  | Ali     | ali@gmail.com   | 312 321


<?php 
session_start();
ob_start();

include 'connect.php';

$email = $_POST['txtEmail'];
$password = $_POST['txtPasswd'];
$cryptpass = md5($password);

$login = mysql_query("select * from users where txtEmail='".$email."' and txtPasswd='".$cryptpass."' ") or die(mysql_error());
if(mysql_num_rows($login))  {
    $_SESSION["login"] = true;
    $_SESSION["user"] = $password;
    $_SESSION["pass"] = $password;
    $_SESSION["email"] = $emailadress;
    header("location:index.php");
}
else
{
    if($email=="" or $password=="") {
        echo "";
    } else {
        header('Location:index.php?error=1');
        exit;
    }
}

ob_end_flush();
?>

这是我的个人资料页面。

<?php
if (empty($_SESSION["fullname"])) {
    $fullnamequery = "";
}






                    if(!empty($_SESSION['login'])) {
                                           echo '<li class="user logged">
                                            <a href="http://www.petkod.com/hesabim/bilgilerim" title="'.$_SESSION['fullname'].'">'.$_SESSION['fullname'].'<span class="arrow"></span></a>
                                            <div class="subMenu">
                                                <ul>
                                                    <li><a href="http://www.petkod.com/hesabim/bilgilerim" class="info">Bilgilerim</a></li>
                                                    <li><a href="http://www.petkod.com/hesabim/petlerim" class="pet">Petlerim</a></li>
                                                    <li><a href="http://www.petkod.com/hesabim/adreslerim" class="address">Adreslerim</a></li>
                                                    <li><a href="http://www.petkod.com/hesabim/siparisler" class="order">Siparişlerim</a></li>
                                                    <li><a href="logout.php" class="logout">Çıkış</a></li>
                                                </ul>
                                            </div>
                                        </li>'; 
}else{echo '<li class="user"><a href="popup-login.php" data-width="520" data-height="556" class="iframe">Giriş Yap</a></li>';};
                    ?>

2 个答案:

答案 0 :(得分:0)

您已创建登录页面。我认为它没有错误。现在,要检索数据,您应该执行另一页profile.php

<?php

session_start();

print_r ($_SESSION);

?>

答案 1 :(得分:0)

尽管有人质疑负面因素,但我还是解决了这个问题。你可以这样做:

$userquery = mysql_query("select * from users where txtEmail='".$email."' and txtPasswd='".$cryptpass."' ");
if(mysql_num_rows($userquery)>0)
{
    header('Location:index.php?error=2');
    exit;
} else {
    $register = "INSERT INTO users (txtName,txtEmail,txtPasswd,txtGsm) VALUES ('$fullname','$email','$cryptpass','$gsm')"; 
    mysql_query("$register") or die(mysql_error()); 
    $_SESSION['login'] = true;
    $_SESSION['fullname'] = $fullname;
    $_SESSION["email"] = $email;
    $_SESSION["gsm"] = $gsm;
    header('location:index.php');}
}