Add php log-in script to html page.

KLM56 used Ask the Experts™

I am working with a html website template that came with fields for user name and password. I have a working php script that user logs into to access restricted pages. My question to you guys,  how can I  make it so that existing html user name and passwords be entered on my html page instead of having to direct the user to php page?

Sample html page is at

php pages is

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

That's a bit confusing.  You can have the original form on an HTML page but the 'action' has to be the PHP page.  In addition, every other page that is being 'protected' by the login must be PHP so you can check the login every time someone accesses the page.


I know it must be confusing, cause I don't even know what I am doing. When you say the action must be the php page. Can you explain for a new be? I read somewhere, that I can add some php script to the html page, but I have to research that some more.

Thanks for your response.
Fixer of Problems
Most Valuable Expert 2014
PHP is a programming language that can be used to put data in a database and check it so you can know if it is a valid login.  HTML is Only a page description language.  You use it to put up a page but it can't be used to access a database or check anything.

At this point, I have to say this login project is beyond you at the moment. has tutorials as does W3Schools  .  It will take quite a while for you to learn enough to complete this project.  This book, PHP & MySQL: Novice to Ninja, is also frequently recommended.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


OK, Thank you....I will do some more research on this.
You most certainly need a script page for database connectivity if you have a user database which could be a database server, text file or xml file .
Option for script could be a php or javascript.
A simple example using php is
where as if you wants to use javascript


Thanks rinfo...

The login php script works fine, I just can't figure how to use my main login as the user input. I will look at your examples and see if it gets me closer. Do appreciate the help.

I have checked your source code .

you just need to put name of your php script which verified login here
<form method="post" action="">
this line should be changed to
<form method="post" action="your php script file name">
Most Valuable Expert 2011
Top Expert 2016
This article is my teaching example that shows all the essential moving parts.  Have a read and let me know if you have any questions.

Going forward in your web experience, just "forget" about HTML pages and think "100% PHP" forever.  PHP is a server-side language that generates HTML.  If you're smart about it, you will write much less HTML and much more PHP because PHP promotes reuse of data objects, including HTML documents.  For your existing HTML pages, you can add the PHP capability by simply parsing HTML documents through PHP.  The parser will ignore anything that is not captioned with <?php start tag, and if you want to add PHP at any time, the parser will use the PHP instructions.

Here is a sample of a web page showing how PHP can make your coding more efficient.
The entire PHP document is here:
<?php //

echo '<p>Hello World</p>' . PHP_EOL;


Open in new window

A good book to help you get a foundation:

Best regards, and welcome to PHP, ~Ray


Thank you guys. This is so much to take in at once, but I want to learn it, so I will read up on all provided information.
Most Valuable Expert 2011
Top Expert 2016

Here are the technologies you will want to master:

Client side:
HTML (5)
CSS (3)
JavaScript, especially jQuery

Server side:

If you like technical books, search for those topics.  Techies are great about reviewing books, so if you find books with lots of positive reviews, those are the ones to go for!


Guys any suggestion for converting the existing website to php? Is there a program that would convert all the existing pages to php. Would I have to manually go into each folder and change if file within the website?

Dave BaldwinFixer of Problems
Most Valuable Expert 2014

I would not suggest converting your site to PHP until you had learned at least the basics.  Of course, the Very first step is to back up your current site, burn it to a CD and save it... just in case.

There is no one click solution for converting an html site to php.
greetings KLM56 , , as said already, you really should take some time and learn the basics of PHP, not just reading about it, but doing very many "Test" scripts (php files on your server), this is particularly important for the database access in PHP code. Setting up database tables with useful and proper columns (fields) and then use INSERT, SELECT and UPDATE  SQL statements to change and get info on database will not happen in a few days of study. But there are hundreds of PHP tutorial web sites and pages available. One of  a php developer's greatest help is learning how to google (yahoo, bing) search for the code examples that you need for a particular project, there's not much in PHP development that has NOT been done already many times.

Maybe this can help you, some "for real" MySQLi (improved) code, many times most of the "Old" MySQL coders do not understand the new coding setups of the Improved version.
$mysqli = new mysqli('localhost', 'user', 'passw', 'DB_name');
	if (!mysqli_connect_errno()) {
		$query = 'INSERT INTO coolo (name1, user1, asoc1, belong2, noton1) VALUES (?,?,?,?,?)';
// IMPORTANT use PREPARE for ALL user input (From POST or GET)
		$stmt = $mysqli->prepare($query);
// execute will READ the REALTIME values of the bind_param variables when execute is called
		$fname = 'Loco Menendez';
		$uname = 'Loco';
// Comma-separated values  CSV data
		$asoc1 = 'TVA,NRA,CCA,DDT,GDC,USA';
		$belong = 533;
		$ton1 = 'DDT';
// IMPORTANT, you MUST Bind the Variables to the the $stmt
		$stmt->bind_param("sssis", $fname, $uname, $asoc1, $belong, $ton1);
		if(!$stmt->execute()) echo 'execute has failed<br>'; else echo 'Rows Inserted '.$stmt->affected_rows.'<br>';
// You can Call $stmt->execute() as many times as you need, just CHANGE the variables for different inserts
		$fname = 'fuffy pink';
		$uname = 'pinky';
		$asoc1 = 'OOH,WOW,HOW,PRE,TTY';
		$belong = 121;
		$ton1 = 'HAT';
// this execute will read the NEW values of the BIND variables
// this is NOT at all like the OLD MySQL function calls
		if(!$stmt->execute()) echo 'execute has failed<br>'; else echo 'Rows Inserted '.$stmt->affected_rows.'<br>';
	echo '<br>Stats : '.$mysqli->stat().'<br>server info : '.$mysqli->server_info.'<br><br>';

// use $mysqli->query just like the OLD MySQL code setups, But it does NOT offer any improved security
	if ($result = $mysqli->query('SELECT * FROM coolo')) {echo 'Number returned rows: '.$result->num_rows.'<br>';
		while ($row = $result->fetch_object()) {echo 'ID: '.$row->id.' user1 '.$row->user1.' name1 '.$row->name1.' asoc1 '.
			$row->asoc1.' belong2 '.$row->belong2.' noton1 '.$row->noton1.'<br>'; 
		} else echo $mysqli->error;
	} else echo '<b>BIG mysqli ERROR - did NOT create the mysqli Object '.mysqli_connect_error().'</b>';

Open in new window

you might do well to learn the improved mysqli instead of MySQL or the "wrapper" PDO stuff.
Most Valuable Expert 2011
Top Expert 2016

...suggestion for converting the existing website to php
This is like converting a bushel of apples into an apple pie -- there are a lot of steps and processes.  But at its simplest, you probably want to make the HTML documents into "units" of the page that can be rendered by PHP.  That means copying the HTML into PHP string variables and using echo to write the strings to the browser output stream.  You can do this best by breaking the HTML up into smaller files and reading the files from the server.  Templating scripts do this sort of thing in all the major frameworks and CMS systems.

I were just starting on this journey, I would start here:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial