douba2011 2018-04-09 14:10
浏览 64

如何使用PHP将唯一用户数据显示到html页面

currently I have a website with a basic login, I was just wondering how I would display a the name,skill and description of the unique user who is logged in.This is what I have done so far.I can only find articles on how to display data into table.This is the updated code:

   <?php
   include('session.php');
   require 'config.php';
   $sql = "SELECT * FROM profile";
   $result = $conn->query($sql);
   //echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
?>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="profile.css">

</head>

<body>



<ul>
  <li><a href="welcome.php">Home</a></li>
  <li><a href="postjob2.php">PostJob</a></li>
  <li><a href="findjob.php">Find Job</a></li>
  <li><a href="hiw2.php">How It Works</a></li>
  <li><a href="notification.php">Notifications</a></li>
  <li><a href="message.php">Message</a></li>
  <li><a href="profile.php">profile</a></li>

</ul>

<h1>Welcome To Bid4MyJob</h1>
  <li><a href="editprofile.php">edit profile</a></li>

<div id="ProfilePage">
    <div id="LeftCol">
        <div id="Photo"></div>
        <div id="ProfileOptions">
        a
        </div>
    </div>

    <div id="Info">
        <p>
            <strong>Name:<?php echo  $row["name"]?></strong>
            <!--<span>James</span>-->
        </p>
        <p>
            <strong>Skill:<?php echo $row["skill"]?><</strong>
            <!--span>James</span>-->
        </p>
        <!-- <p>
            <strong>review:<?php /*echo $row["review"]*/?><</strong>
            <span>james</span>
        </p> -->
        <p>
            <strong>Description:<?php echo $row["description"]?><</strong>
            <span>James</span>
        </p>
        <!--<p>
            <strong>Name:</strong>
            <span>james</span>
        </p>-->
    </div>

    <!-- Needed because other elements inside ProfilePage have floats 
    <div style="clear:both"></div>-->
</div>
</body>
</html>

Picture of database table:

https://imgur.com/a/XYTLY

Session.php:

<?php
   include('config.php');
   session_start();

   $user_check = $_SESSION['login_user'];

   $ses_sql = mysqli_query($conn,"select email_adress from customer where email_adress = '$user_check' ");

   $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);

   $login_session = $row['email_adress'];

   if(!isset($_SESSION['login_user'])){
      header("location:login.php");
   }
?>

Login.php:

<?php
   include("config.php");
   session_start();

   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 

      $myusername = mysqli_real_escape_string($conn,$_POST['username']);
      $mypassword = mysqli_real_escape_string($conn,$_POST['password']); 

      $sql = "SELECT customer_id FROM customer WHERE email_adress = '$myusername' and password = '$mypassword'";
      $result = mysqli_query($conn,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
      $active = $row['customer_id'];

      $count = mysqli_num_rows($result);

      // If result matched $myusername and $mypassword, table row must be 1 row

      if($count == 1) {

         $_SESSION['login_user'] = $myusername;

         header("location: index2.php");
      }else {
         $error = "Your Login Name or Password is invalid";
      }
   }
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Login | Bid4MyJob</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Bid4MyJob">
    <meta name="author" content="James Wood">
    <!-- CSS -->
    <link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css">
    <link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/main.css" rel="stylesheet" type="text/css">
    <link href="assets/css/my-custom-styles.css" rel="stylesheet" type="text/css">

    <!-- IE 9 Fallback-->
    <!--[if IE 9]>
        <link href="assets/css/ie.css" rel="stylesheet">
    <![endif]-->
    <!-- GOOGLE FONTS -->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400italic,400,600,700' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:300,300italic,400italic,700,400,300' rel='stylesheet' type='text/css'>
    <!-- FAVICONS -->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/repute144x144.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/repute114x114.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/repute72x72.png">
    <link rel="apple-touch-icon-precomposed" href="assets/ico/repute57x57.png">
    <link rel="shortcut icon" href="assets/ico/favicon.png">
</head>

<body>
    <!-- WRAPPER -->
    <div class="wrapper">
        <!-- NAVBAR -->
        <nav class="navbar navbar-default " role="navigation">
            <div class="container">
                <!-- TOPBAR -->
                <div class="topbar">
                    <ul class="list-inline top-nav">
                        <li>
                            <div class="btn-group">
                                <button type="button" class="btn btn-link dropdown-toggle btn-xs" data-toggle="dropdown"><img src="assets/img/flags/United-Kingdom.png" alt="United Kingdom"> United Kingdom <span class="caret"></span></button>
                                <ul class="dropdown-menu dropdown-menu-right country-selector" role="menu">
                                    <li>
                                        <a href="#"><img src="assets/img/flags/United-Kingdom.png" alt="United Kingdom"> United Kingdom</a>
                                    </li>
                                    <li>
                                        <a href="#"><img src="assets/img/flags/Japan.png" alt="Japan"> Japan</a>
                                    </li>
                                    <li>
                                        <a href="#"><img src="assets/img/flags/China.png" alt="China"> China</a>
                                    </li>
                                    <li>
                                        <a href="#"><img src="assets/img/flags/Germany.png" alt="Germany"> Germany</a>
                                    </li>
                                </ul>
                            </div>
                        </li>
                        <li><a href="#">Help</a></li>
                        <li><a href="#">Support</a></li>
                    </ul>
                    <div class="searchbox">
                        <form method="post">
                            <div class="input-group input-group-sm">
                                <input type="text" class="form-control" placeholder="search ...">
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="button"><i class="fa fa-search"></i></button>
                                </span>
                            </div>
                        </form>
                    </div>
                </div>
                <!-- END TOPBAR -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-nav">
                        <span class="sr-only">Toggle Navigation</span>
                        <i class="fa fa-bars"></i>
                    </button>
                    <a href="index.html" class="navbar-brand navbar-logo navbar-logo-bigger">

                    </a>
                </div>
                <!-- MAIN NAVIGATION -->
                <div id="main-nav" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="index.php">HOME</a>
                        </li>
                        <li>
                            <a href="HIW.php">HOW IT WORKS</a>
                        </li>
                        <li>
                            <a href="postjob.php">POST JOB</a>
                        </li>
                        <li>
                            <a href="findjob.php">FIND JOB</a>
                        </li>
                        <li>
                            <a href="signup.php">SIGN UP</a>
                        </li>
                        <li>
                            <a href="login.php">LOGIN</a>
                        </li>
                    </ul>
                </div>
                <!-- END MAIN NAVIGATION -->
            </div>
        </nav>
        <!-- END NAVBAR -->
        <!-- BREADCRUMBS -->
        <div class="page-header">
            <div class="container">
                <h1 class="page-title pull-left">Login</h1>
                <ol class="breadcrumb">
                    <li><a href="#">Home</a></li>
                    <li class="active">Login</li>
                </ol>
            </div>
        </div>
        <!-- END BREADCRUMBS -->
        <!-- PAGE CONTENT -->
        <div class="page-content">

                            <div class="col-md-6">
                                <!-- LOGIN FORM -->
                                <h2 class="section-heading">Login Form</h2>
                                <form class="form-horizontal" role="form" action = "" method = "post">
                                    <div class="form-group">
                                        <label for="username" class="control-label sr-only">Email</label>
                                        <div class="col-sm-12">
                                            <div class="input-group">
                                                <input type="email" class="form-control" id="username" name = "username" placeholder="Email">
                                                <span class="input-group-addon"><i class="fa fa-envelope"></i></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="password" class="control-label sr-only">Password</label>
                                        <div class="col-sm-12">
                                            <div class="input-group">
                                                <input type="password" class="form-control" id="password" name="password" placeholder="Password">
                                                <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-12">
                                            <label class="fancy-checkbox">
                                                <input type="checkbox">
                                                <span>Remember me</span>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-12">
                                            <button type="submit" class="btn btn-primary"><i class="fa fa-sign-in"></i> Sign in</button>
                                        </div>
                                    </div>
                                </form>
                                <br>
                                <p><em>Don't have an account yet?</em> <a href="#"><strong>Sign Up</strong></a>
                                    <br>
                                    <em>Forgot your password?</em> <a href="#">Recover Password</a></p>
                                <!-- END LOGIN FORM -->
                            </div>
                        </div>
                        <br>
                        <br>
                        <div class="row">
                            <div class="col-md-6">
                                <!-- LOGIN FORM WITH LABEL -->

                                <!-- END LOGIN FORM WITH LABEL -->
                            </div>
                            <div class="col-md-6">
                                <!-- SIMPLE FORM -->

                                <!-- END SIMPLE FORM -->
                            </div>
                        </div>
                        <br>
                        <br>
                        <!-- INLINE FORM -->

                        <!-- END INLINE FORM -->
                    </div>
                </div>
            </div>
        </div>
        <!-- END PAGE CONTENT -->
        <!-- FOOTER -->
        <footer>
            <div class="container">
                <div class="row">
                    <div class="col-md-4">
                        <!-- COLUMN 1 -->
                        <h3 class="sr-only">ABOUT US</h3>
                        <img src="assets/img/logo/repute-logo-light.png" class="logo" alt="Repute">
                        <p>Proactively aggregate B2B initiatives before extensive channels. Monotonectally extend interactive methods of empowerment through excellent applications. Rapidiously synergize visionary products with sticky technology.</p>
                        <br>
                        <address class="margin-bottom-30px">
                            <ul class="list-unstyled">
                                <li>Unit 5, Block B Nesfield Road
                                    <br/> Colchester, Essex CO4 3ZL 222222</li>
                                <li>Phone: 01206 588 000</li>
                                <li>Email: sales@universalwebdesign.co.uk</li>
                            </ul>
                        </address>
                        <!-- END COLUMN 1 -->
                    </div>
                    <div class="col-md-4">
                        <!-- COLUMN 2 -->
                        <h3 class="footer-heading">USEFUL LINKS</h3>
                        <div class="row margin-bottom-30px">
                            <div class="col-xs-6">
                                <ul class="list-unstyled footer-nav">
                                    <li><a href="#">About Us</a></li>
                                    <li><a href="#">News</a></li>
                                    <li><a href="#">Community</a></li>
                                    <li><a href="#">Career</a></li>
                                    <li><a href="#">Blog</a></li>
                                </ul>
                            </div>
                            <div class="col-xs-6">
                                <ul class="list-unstyled footer-nav">
                                    <li><a href="#">Press Kit</a></li>
                                    <li><a href="#">FAQ</a></li>
                                    <li><a href="#">Terms</a></li>
                                    <li><a href="#">Privacy Policy</a></li>
                                    <li><a href="#">Contact Us</a></li>
                                </ul>
                            </div>
                        </div>
                        <!-- END COLUMN 2 -->
                    </div>
                    <div class="col-md-4">
                        <!-- COLUMN 3 -->
                        <div class="newsletter">
                            <h3 class="footer-heading">NEWSLETTER</h3>
                            <p>Get the latest update from us by subscribing to our newsletter.</p>
                            <form class="newsletter-form" method="POST">
                                <div class="input-group input-group-lg">
                                    <input type="email" class="form-control" name="email" placeholder="youremail@domain.com">
                                    <span class="input-group-btn"><button class="btn btn-primary" type="button"><i class="fa fa-spinner fa-spin"></i><span>SUBSCRIBE</span></button>
                                    </span>
                                </div>
                                <div class="alert"></div>
                            </form>
                        </div>
                        <div class="social-connect">
                            <h3 class="footer-heading">GET CONNECTED</h3>
                            <ul class="list-inline social-icons">
                                <li><a href="#" class="facebook-bg"><i class="fa fa-facebook"></i></a></li>
                                <li><a href="#" class="twitter-bg"><i class="fa fa-twitter"></i></a></li>
                                <li><a href="https://plus.google.com/115190620540200390059" class="googleplus-bg"><i class="fa fa-google-plus"></i></a></li>
                                <li><a href="#" class="rss-bg"><i class="fa fa-rss"></i></a></li>
                            </ul>
                        </div>
                        <!-- END COLUMN 3 -->
                    </div>
                </div>
            </div>
            <!-- COPYRIGHT -->
            <div class="text-center copyright">
                &copy;2018 Bid4MyJob. All Rights Reserved.
            </div>
            <!-- END COPYRIGHT -->
        </footer>
        <!-- END FOOTER -->
    </div>
    <!-- END WRAPPER -->
    <!-- JAVASCRIPTS -->
    <script src="assets/js/jquery-2.1.1.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/plugins/autohidingnavbar/jquery.bootstrap-autohidingnavbar.min.js"></script>
    <script src="assets/js/repute-scripts.js"></script>

</body>

</html>
  • 写回答

1条回答 默认 最新

  • duanhe1903 2018-04-09 14:39
    关注

    You need a field on Profile that links to the customer table (or viceversa).

    email can be in both tables, then you can link to your $login_session

    SELECT * FROM profile WHERE email = '$login_session' LIMIT 1
    

    In this case, take care and do not let users to change their email (without verification they own it) and do not let create a new account with the same credentials as another one.

    But as a good practice on DB, it is better to have profile_id on customer

    session.php

    $ses_sql = mysqli_query($conn,"select email_adress, profile_id from customer where email_adress = '$user_check' ");
    

    index.php

    $sql = "SELECT * FROM profile WHERE profile_id = $profile_id LIMIT 1";
    

    BTW: - Try to separate concerns, between database and presentation layer. You should read more about MVC.

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决