Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to create a database-driven user homepage based on register in PHP

    Hi Friends!

    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 Code:
    <?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($passwordPASSWORD_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
    Code:
    <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

    PHP Code:
    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;
      }

    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

  2. #2
    New to the CF scene
    Join Date
    Nov 2017
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi, you can check udemy academy for some videos on this topic....

  3. #3
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    3,086
    Thanks
    4
    Thanked 447 Times in 436 Posts
    Whilst I can't quite decipher what it is you are asking, your code has a LOT of issues.

    PHP-side you're slopping your variables into the query strings like you are still using the horribly and terrifyingly outdated mysql_ functions. It's called prepare/execute, USE IT! Then you could scrap those garbage p_s functions whatever the blazes that nonsense is.

    HTML-wise placeholder is not a <label> and anyone telling you to build a form that way needs a quadruple helping of sierra tango foxtrot uniform. Where are your <label>'s? Where are your <fieldset>? If you're building a form that way, sorry to say you don't know enough HTML to be playing with PHP yet!

    Re-reading it again... and again... I think what you are asking for is a many-to-one / one-to-many approach. You have multiple 'groups and/or modules' the user when creating their account can be associated with, right?

    Nope, still can't figure out what you're asking. What's this "contentID" thing?
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    http://www.cutcodedown.com

  4. #4
    New Coder
    Join Date
    Mar 2017
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i am guessing that p_s is his password salt function, and contentID is indended to hold UserDemo, course and module depending on what they select during registration.

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,236
    Thanks
    12
    Thanked 116 Times in 114 Posts
    Hi, without seeing your table schema its hard to know where to start, essentially you want to store details of the courses relevant to a particular user, one way is a lookup table.
    Essentially you get the user to select the modules/courses they want and store those module/course id's in another db table along with their user id's.
    When the user logs in you search the lookup table for all modules associated with that ID.

    Post the structure of your user and module tables.

    @deathshadow "sorry to say you don't know enough HTML to be playing with PHP yet!" , if HTML/CSS skills are some sort of pre-requisite for the ability to use and learn PHP, well that's news to me.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  6. #6
    Master Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    5,277
    Thanks
    121
    Thanked 621 Times in 607 Posts
    Quote Originally Posted by firepages View Post
    @deathshadow "sorry to say you don't know enough HTML to be playing with PHP yet!" , if HTML/CSS skills are some sort of pre-requisite for the ability to use and learn PHP, well that's news to me.
    Yup! I use php just to automate some tasks that I don't want the hassle of compiling a windows app for.

    DS needs to accept that php isn't just about page development but about how and why you use it.

  7. #7
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    3,086
    Thanks
    4
    Thanked 447 Times in 436 Posts
    Quote Originally Posted by firepages View Post
    @deathshadow "sorry to say you don't know enough HTML to be playing with PHP yet!" , if HTML/CSS skills are some sort of pre-requisite for the ability to use and learn PHP, well that's news to me.
    What part of the recursive backronym did you miss? Just what are you outputting with your PHP, marzipan and kittens?

    PHP was created to glue database access to HTML, as such if you don't know "HyperText Markup Language" well enough to create valid and proper semantic markup such as complete accessible forms to send data to PHP WITH, you probably aren't going to fare very well at using a "PHP : Hypertext Preprocessor"

    It's in the bloody name!
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    http://www.cutcodedown.com


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •