0

I am having a problem allowing users (teachers) to have their own sections. A section will allow a teacher that registers access to only their students and questions posted by them. When a teacher registers, they will be given a unique number that allows them access to a new separate section.

I have one users table that is filled with students and teachers. I tried adding another column or table for students and teachers with the same section number but I have not been able to get it to work.

Also the id I am using in phpMyAdmin, I am using as a student id number. I tried to use it as a section number which took away the ability to recognize each students' answers in my database (since they are stored as an id). I hope this is clear and thank you all ahead of time.

Here is my users table in my database.

enter image description here

And here is my register.php code...it is deprecated as of now (working on switching it to mysqli later)

<!DOCTYPE html>
<html>
<head>
    <title>Registration</title>
    <link rel="stylesheet" href="main.css">
</head>

<body class="login" style="margin-bottom: 100px; " >

    <?php include 'connect.php'; ?>

    <?php include 'functions.php'; ?>

<span style="display: inline-block;"><h1 style="margin-left: 40px; ">Register</h1></span><span style="display: inline-block; padding-left: 165px; "><a href="login.php"><p>Back</p></a></span>
<link rel="stylesheet" href="main.css">

<form action="" method="post">
    <ul>
        <li>
            <input type="text" name="username" class="box" size="25" placeholder="Username"><br>
        </li>
        <li>
            <input type="password" name="password" class="box" size="25" placeholder="Password"><br>
        </li>
            <br><br>
            <button type="submit" style="margin-bottom: 5px;" class="subbutton" name="submit">Register</button>
        </li>
    </ul>   
</form>

    <?php

            if(isset($_POST["submit"])){

            if(!empty($_POST['username']) && !empty($_POST['password'])) {
            $username=$_POST['username'];
            $password=$_POST['password'];

            $con=mysql_connect('localhost','root','') or die(mysql_error());
            mysql_select_db('project') or die("Cannot select database");

            $query=mysql_query("SELECT * FROM users WHERE username='".$username."'");
            $numrows=mysql_num_rows($query);
            if($numrows==0)
            {
            $sql="INSERT INTO users VALUES('','$username','$password','','','','1','d')";

            $result=mysql_query($sql);


            if($result){
            echo "Account successfully created!";
            } else {
            echo "Didn\'t work, try again";
            }

            } else {
            echo "That user ID already exists! Please try again";
            }

            } else {
            echo "All fields are required!";
        }
    }

    ?>

</body>
</html>
Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
  • The `mysql_*` functions in PHP are deprecated and shouldn't be used. Please read [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) for information on why and what to replace them with. – Matt Raines May 01 '16 at 22:19
  • Yea I know, I have a lot of `mysql_*` code that is deprecated. I am working on switching to `mysqli` later. Thank you for the link to help. – user6005619 May 01 '16 at 23:52

0 Answers0