如何在PHP中基于寄存器创建数据库驱动的用户主页 [英] How to create a database-driven user homepage based on register in PHP

查看:161
本文介绍了如何在PHP中基于寄存器创建数据库驱动的用户主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你有任何见解,我有一个我会爱你帮助的困境。简而言之,我目前正在做一个研究门户类型的项目,我希望它完全由数据库驱动,这样当我注册一个模块时,该特定模块出现在用户的个人资料中,因为截至目前,它并没有无论tom,dick还是harry登录,他们都会看到特定课程的三个模块。



因此,在注册时,用户会选择一门课程,将出现相关模块列表,然后用户将选择其模块。从那时起,他们的主页将填充html&附加到该模块的CSS代码。



有3个表与此部分交互。 UserDemo,课程和模块。



以下是我目前注册为用户的代码(必须添加课程和模块)



accounts\signup.php



I've got a predicament that I'd love your help with if you have any insight. In Short, I'm currently doing a study portal type project and I'm looking to have it fully database driven so that when I register for a module, that particular module appears on the user's profile because as of right now, it doesn't matter if tom, dick or harry logs in, they all see the same three modules for a particular course.

So upon registering, a user would choose a course, a list of relevant modules would appear and then a user would choose their modules. From that, their homepage would be populated by the html & CSS code attached to that module.

There's 3 tables that interact with this section. UserDemo, course and module.

Here is the code I have to do with registering as a user currently (the course & modules must be added)

accounts\signup.php

<?php 
    include '../inc/db.php';
    include '../inc/functions.php';


    if (isset($_POST['signup'])) {
        $fName = p_s($_POST['fName']);
        $lName = p_s($_POST['lName']);
        $email = p_s($_POST['email']);
        $password = p_s($_POST['password']);
        $rpassword = p_s($_POST['rpassword']);
        $contentID = p_s($_POST['contentID']);
        if (!empty($fName) && !empty($lName) && !empty($email) && !empty($password) && !empty($contentID)) {
            if (strlen($password) === strlen($rpassword)) {

          $options = [
              'cost' => 12,
          ];
          $password = password_hash($password, PASSWORD_BCRYPT, $options);
          $created_at = date('Y-m-d G:i:s');

                $sql = "INSERT INTO usersDemo (fName, lName, email, password, contentID, status, created_at) VALUES ('$fName','$lName', '$email', '$password', '$contentID', 'approved', '$created_at')";
                if (mysqli_query($conn, $sql)) {
                    header('Location: ../signup.php?suc');exit();
                }
            }else{
                header('Location: ../signup.php?fidpass');exit();
            }
        }else{
            header('Location: ../signup.php?fempt');exit();
        }


    }







inc\signup.php







<form action="accounts/signup.php" method="POST">

      <div id="fade-box">
        <h2>Register</h2>
     <div class="form-group">
       <input name="fName" type="text" class="form-control" id="fName" placeholder="Enter your first name" required>
     </div>
     <div class="form-group">
       <input name="lName" type="text" class="form-control" id="lName" placeholder="Enter your last name" required>
     </div>
     <div class="form-group">
       <input name="email" type="email" class="form-control" id="email" placeholder="Email" required>
     </div>
     <div class="form-group">
       <input name="password" type="password" class="form-control" id="password" placeholder="Password" required>
     </div>
     <div class="form-group">
       <input name="rpassword" type="password" class="form-control" id="rpassword" placeholder="Repeat Password" required>
     </div>
     <div class="form-group">
       <input name="contentID" type="text" class="form-control" id="contentID" placeholder="Enter your contentID" required>
     </div>
     <button name="signup" type="submit" class="btn btn-success">Register</button>
     </div>
   </form>







全局登录验证功能






Global Functions for login validation

function checkIfEmailExist($email){
  global $conn;
  $data[]=array();
  $sql = "SELECT userID FROM usersDemo WHERE email ='$email'";
  $run = mysqli_query($conn, $sql);
  $rows =mysqli_num_rows($run);
  if ($rows == 0) {
    return false;
  }else{
    return true;
  }
}


function checkPassword($email, $password){
  global $conn;
  $sql = "SELECT password FROM usersDemo WHERE email ='$email'";
  $run = mysqli_query($conn, $sql);
  while ($rows = mysqli_fetch_assoc($run)) {
    $hashedDBPass = $rows['password'];
  }
  if (password_verify($password, $hashedDBPass)) {
    return true;
  }else{
    return false;
  }
}





我的尝试:



这是我目前的攻击计划:





从中选择模块名称,模块描述db



在屏幕上显示



迭代值并显示



将UI的代码复制到for循环中



您对此攻击计划的看法是什么,或者有人知道替代方案(也许是更简单)实现这一目标的方式。



提前感谢您的时间和帮助:)



What I have tried:

This is my current plan of attack:


Select module name, module description from db

Display on screen

Iterate through values and display

Copy code for UI into for loop

What would your opinions be on this plan of attack or does anyone know of an alternative (and maybe easier) way of accomplishing this.

Thanks in advance for your time and help :)

推荐答案

_POST ['signup'])){
_POST['signup'])) {


fName = p_s(
fName = p_s(


_POST ['fName']);
_POST['fName']);


这篇关于如何在PHP中基于寄存器创建数据库驱动的用户主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆