尝试创建用户配置文件但遇到一些问题

时间:2015-09-17 21:20:05

标签: php

我是php的新手,我正在尝试创建一个用户配置文件来显示数据库中的信息。我的问题是我一直在“你需要指定用户名!”这是来自我的if语句的回声。

你能指出我为什么没有显示用户名吗?

以下是我的个人资料代码。

<?php
    //check for a form submission
    if (isset($_GET['username'])){
        $username = $_GET['username'];
        $q = "SELECT * FROM student WHERE username = '$username'";
        $r = mysqli_query($dbc, $q);

        if(mysqli_num_rows($r) == 1) {

            die ("that user name could not be found!");
        }
        while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){
            $firstname = $row['firstname'];
            $lastname = $row['lastname'];
            $age = $row['age'];
        }
?>
<?php
        } else die ("you need to specify a username!");
?>

以下是登录

<?php 

# Database Connetion:
include('config/setup.php');  


# Loggin authentication
if($_POST) {

    $q = "SELECT * FROM student WHERE username = '$_POST[user]' AND password = SHA1('$_POST[password]')";
    $r = mysqli_query($dbc, $q);


    if( mysqli_num_rows($r) == 1) {

        $_SESSION['username'] = $_POST['user'];
        header('Location: profile.php');

    }


}

 ?>

以下是我的数据库连接和会话开始

<?php
//Setup File:

#Start Session:
session_start();

# Database Connection Here...
$dbc = mysqli_connect('localhost', 'dev', 'dev123', 'mvt') OR die ('Could not connect because: '.mysqli_connect_error());



?>

我在连接文件中设置会话开始,并使用下面的include函数调用它。

<?php include('config/setup.php'); ?>

很抱歉,如果我的代码很乱,我是PHP的新手,我仍然试图掌握它。

<title><?php echo $page_title.' | '.$site_title; ?> </title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<?php include('config/css.php'); ?>
<?php include('config/js.php'); ?>

  <div class="container">


  <div class="masthead">
    <h3 class="text-muted"></h3>
    <nav>
      <ul class="nav nav-justified">
        <li class="active"><a href="index.php">Home</a></li>
        <li><a href="#">Projects</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Downloads</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </nav>
  </div>

    </div>



  <div class="container">

        <div class="row">


            <div class="col-md-4 col-md-offset-4">

                    <div class="panel panel-info">

                    <div class="panel-heading">
                        <strong>Login</strong> 
                    </div><!-- END Pannel heading -->


                        <div class="panel-body"> 



                            <form action="login.php" method="post">

                              <div class="form-group">
                                <label for="user">UserName</label>
                                <input type="text" class="form-control" id="user" name="user" placeholder="UserName">
                              </div>


                              <div class="form-group">
                                <label for="password">Password</label>
                                <input type="password" class="form-control" id="password" name="password" placeholder="Password">
                              </div>

                             <!--
                              <div class="checkbox">
                                <label>
                                  <input type="checkbox"> Check me out
                                </label>
                              </div>
                              --> 

                              <button type="submit" class="btn btn-default">Login</button>
                              <a href="registration.php">register</a>
                            </form> <!-- END of form -->

                        </div> <!-- END of pannel body -->

            </div><!-- END of Column -->

        </div><!-- END of ROW -->

        </div> <!-- END of container -->





<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>

1 个答案:

答案 0 :(得分:0)

header('Location: profile.php')正在重定向您的浏览器 - 因此profile.php正在独立于其余代码执行。将其更改为include('profile.php')而不是