mysql php html login user database hidden code

My question is a bit theory than asking for code. I created this website using html. I don’t like using other peoples code, plugins. I want to create a table in sql with user names and passwords. Then force people to logon.

The code that deals with MY connection to the database has to be hidden from the user for obvious reasons. Conceptually how would i do that?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nothing wrong with using other people's code - we all do it!

Conceptually you need your database as you realise, then you have a FORM where the visitor can enter their username and password
When they click submit they are passed to another page that gets the username and password and does a select against the db with that data. If nothing is returned then the user doesn't exist, if you get the row with that data back then they do exist and you can 'log them in'
That is just the basics - there is a lot more to it like sanitizing your data, encrypting your passwords, how to store the user state etc

You don't need to worry about your db connection - it is written in PHP and will never be seen by the user.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Giovanni HewardCommented:
Create an include file which is stored in a folder structure not publicly accessible.

For example d:\apache\htdocs\ you could store as d:\includes\dbconnect.php

Instead of ...
 // Connects to Our Database 
 mysql_connect("", "username", "password") or die(mysql_error()); 
 mysql_select_db("Database_Name") or die(mysql_error()); 

Open in new window

You'd just include this line:

 //MySQL Database Connect
 include '/includes/dbconnect.php'; 

Open in new window

Or you'd provide default credentials in your php.ini file, which is also stored in a folder not publicly accessible.

Then you'd just use:
mysql_connect() or die(mysql_error()); 
mysql_select_db("Database_Name") or die(mysql_error()); 

Open in new window

Generally you just put the file with the connect function in a folder above the root, so it is not accessible from the browser then you just include the connect in page where you will need to access the db.

This is a basic login form that you should be able to customize for your requirements.

Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Ray PaseurCommented:
Every web site that does this (correctly) follows the same general design.  This article explains how it's done, complete with code samples.

The "Login" article is rather old, and today you would choose the MySQLi or PDO extension to access the data base.  This article maps the extensions showing how to accomplish the conversion from procedural MySQL to a newer extension.  In my experience the easiest conversion for existing MySQL code is the MySQLi object-oriented code.

And if you're new to PHP, this article will point you to some good learning resources.
RoodonaAuthor Commented:
   Just a update I’m currently working on all of your recommendations. Thanks for your responses it has been so helpful!!
RoodonaAuthor Commented:
Everyone had great input and I much appreciate your help. Thank you so much for your time!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.