In the following you can see the very first draft of the posting site. So far, the “sign up” function does not work because of an unknown bug but after remotely signing the user up (using INSERT INTO database), the user can log in (here, the connection works) and write posts. Those posts are then echoed out on the site and saved in the database. I let my friends try that very simple version. So far the posts are just echoed out, one after another. There is no working sorting system or boxed around the posts.
Before I could put code in my connect.php file and connect to the database, I had to set up the categories that I wanted. I had to start with something and since there was a lot that had to be considered, I decided to start of simple and then improve my work once I had a clearer view of what to do. That’s why I only created two tables, the two most important and basic ones. The first one was the “users” table. Its purpose is to store the users’ details once they have registered. The second one was the “posts” table that our website would need to store the tweets/posts and information about who made them.
Here you can see both of the tables I set up:
As you might notice, both of them have an ID column. The data that will end up in that column will not be entered by the user. Instead it will automatically enter every time a new entry is added to the table. It is a simple number, starting at 1 counting up. Unlike names or maybe passwords, none of the numbers will ever repeat or be reused, not even if users delete their account. That has the purpose of creating a unique version of identifying a user.
To get this done, I had to enter some extra settings for the ID column. First of all, I had to make it a PRIMARY KEY. The PRIMARY KEY pretty much does what I just explained; it uniquely identifies each record in a database table. The other thing that is important to take of is the extra AUTO_INCREMENT which does the auto filling and counting up part of the value.
Next to the ID column, the “users” table also in equipped with a “Data of Entry” column. This is not particularly necessary right now, but later we will have to use it to determine the users Year of University (note: the year has to change over time). To do that, I will also have to create a column that states the first value entered, but more to that later.
The other columns are just the values the user enters.
Now that the tables are set up, it is time to connect our website to the database:
$connect = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
die(“Database connection failed: ” .
” (” . mysqli_connect_errno() . “)”