Basic Question

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu Apr 11, 2013 5:33 am

Basic Question

Postby lukenichols » Thu Apr 11, 2013 5:38 am

Hi guys.

I am new to PHP and website design and also new to the forums.

I am basically trying to teach myself as much as possible about PHP, HTML, SQL & CSS.

I am planning to start by building a simple website. I have already designed a very simple log in screen in a .HTML document.

Here is the current code for my log in page.

<!DOCTYPE html>
<form action="Loginprocess.php">
<input type="text" name="username" size="20" maxlength="20" />
<br />
<input type="password" name="password" size="20" maxlength="20" />
<br />
<input type="submit"/>
<br />



So am I correct to think this page will access the loginprocess.php document once the user clicks the submit button?

My question is, once the user clicks the submit button, the loginprocess.php document will be accessed which is effectively changing web page is it not? How can I carry the values from the user entry boxes over to the loginprocess.php document (to check if they are valid)?

For now, I would simply like my loginprocess.php document to open the Main.html document. (I will code the data validation etc later on).

So I basically need to know if I am going down the right route here? And I would also like to know how to open another web page in php code.

Thanks guys


User avatar
php-forum Active User
php-forum Active User
Posts: 253
Joined: Sat Mar 23, 2013 8:24 am

Re: Basic Question

Postby Strider64 » Thu Apr 11, 2013 7:54 am

I use a hidden type for older version of Internet Explorer sometimes flakes out at the submit button. You have to have the method="post" in you form statement.

Code: Select all

<form class="login-form" action="login.php" method="post">
                     <input type="hidden" name="action" value="login" >
                     <label class="input-style" for="username">User Name</label>
                     <input type="text" onfocus="if (this.value == 'User Name') this.value = '';" value="User Name" name="username" id="username" >
                     <label class="input-style" for="password">Password</label>
                     <input type="password" name="password" id="password" value="" >
                     <input type="submit" id="login" value="Login" >
                     <a class="link-style" href="captcha.php" target="_self">Register?</a>

Then in you the login.php (or whatever filename it is) you might do something like the following:

Code: Select all


define('DB_HOST', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '****');
define('DB_NAME', 'your_database');

header('Content-Type: text/html; charset=utf-8');
/* I usually put the above in a separate file called common.php */
/* then i simple just put it at the top of my php file                 */
/* <?php require("includes/common.php"); ?>                         */

if (isset($_POST('action')) {
   if ($_POST('action') == 'login') {
        $username = htmlspecialchars($_POST('username')); // Make sure you encapsulate any variable that a user can change.
        $password = htmlspecialchars($_POST('password')); // Make sure you encapsulate any variable that a user can change.
        //......more php code to check user's credentials

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 6 guests