D4DME – Creating Sign Up Form/Meeting with Kyle

The way in which we create a sign-up form is different to how we made the login form. The login form uses the query ‘SELECT * FROM’ which means that it looks up existing users already uploaded into the database and grants them access if they exist. Below is the code which shows the back end process of connecting to the database. The ‘$_SESSION [“message”]’ and ‘$_SESSION [“username”]’ create a message which pops up when the user successfully logs in and reads “Success, welcome back {username}”. If the user fails to log in “Wrong username/password” pops up.

login request

When it came to figuring out how to manipulate the above code to allow users to sign up with a username and password was the difficult part. We created a new page called ‘signup.php’ and used the same code and just edited the various sections – however when a user tried to input their new details, they didn’t submit into the database.

We looked online for some solutions to help us but we could seem to get it to work so we decided to arrange a meeting with Kyle to see if he could help explain to us where we were going wrong. He immediately saw the problem and it was that instead of ‘SELECT * FROM’ it should be ‘INSERT INTO’ as you are adding information to the database not selecting it. Once we altered this – users were able to sign up and then login with their username and password. The code for the sign up page is below.

signup code

Whilst we were with Kyle in the meeting we asked him if it would be possible to remove the option to login and sign up once the user had logged in and instead show up the ‘New Post’ button. He managed to show us using an existing project he had worked on so we could decide how we wanted it to look. In order to do this we had to work in the index.php file and write out code which translates to “if the user is not logged in then include the login and signup button on the page” this meant that when the user is logged in, the login and signup buttons will not appear.

login:signup in user loggin


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s