Add php log-in script to html page.

Posted on 2012-12-27
Last Modified: 2013-11-26

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

Question by:KLM56
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +2
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38725672
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.

Author Comment

ID: 38725704
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.
LVL 83

Accepted Solution

Dave Baldwin earned 125 total points
ID: 38725734
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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 38725741
OK, Thank you....I will do some more research on this.

Assisted Solution

rinfo earned 125 total points
ID: 38726480
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

Author Comment

ID: 38726535
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.

Expert Comment

ID: 38726546
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">
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
ID: 38726759
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

Author Comment

ID: 38727823
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.
LVL 110

Expert Comment

by:Ray Paseur
ID: 38728150
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!

Author Comment

ID: 38728250
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?

LVL 83

Expert Comment

by:Dave Baldwin
ID: 38728449
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.

Expert Comment

ID: 38728543
There is no one click solution for converting an html site to php.
LVL 34

Assisted Solution

Slick812 earned 125 total points
ID: 38729644
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.
LVL 110

Expert Comment

by:Ray Paseur
ID: 38734499
...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:

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question