Could somebody please help me implement this HTML with my PHP login Page?
For some reason, the page is unresponsive.
Here is the HTML code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" href="css/screen.css" type="text/css" />
<!--[if ite - 8]><link rel="stylesheet" href="css/screen_ie.css" type="text/css" /><![endif]-->
<meta http-equiv="content-type" content="text/html; charset=windows-1251" />
<title>Index</title>
</head>
<body>
<div id="block">
<div class="logo"><img src="img/logo.png" alt="" /></div>
<div class="form">
<p class="login-box">Login box</p>
<div class="warning"><p>Wrong password, please try again.</p><p class="c"> </p></div>
<input type="text" value="Username"/>
<input type="text" value="*******"/>
<p class="btn">
<input type="button" value="Login"/>
</p>
<ul class="nav-path">
<li><a href="#">Forgot your password?</a></li>
<li><a href="#">Create new account</a></li>
</ul>
<i class="ctop"> </i>
<i class="cbottom"> </i>
</div>
</div>
</body>
</html>
And here is the current PHP login page with a temporary form:
<?php
include("db.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$password = sha1($password);
$sql="SELECT * FROM client_login WHERE Username='$username' and Password='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$row = mysql_fetch_array($result);
$client_ref = $row['Client_ref'];
$user_level = $row['user_level'];
// If result matched $username and $password, table row must be 1 row
if($count==1)
{
$_SESSION['user_level'] = $user_level;
$_SESSION['client_ref'] = $client_ref;
$_SESSION['user'] = $username;
if ($user_level == '1') {
header('Location: admin.php');
} else {
header('Location: myaccount.php');
}
}
else
{
echo "Error logging in!";
}
}
?>
<form action="login.php" method="post">
<label>UserName :</label>
<input type="text" name="username"/><br />
<label>Password :</label>
<input type="password" name="password"/><br/>
<input type="submit" value=" Login "/><br />
</form>
Any suggestions or ideas would be greatly appreciated.
There appears to be multiple problems with your code that you posted. For starters as I stated above in a comment, I don’t recognize the conditional comment
ite - 8. Make sure that comment is correct and use this site as a reference.In addition, you are trying to send input with no form. A div with a
class="form"is not the same as an actual form. Inside<div class="form">add the following:Fill in action with the page you are posting to.
After this line:
<i class="cbottom"> </i>add a closing form tag like so:Finally, change your button from
type="button"totype="submit".So to recap, check the conditional comment. This shouldn’t stop your page from loading however. Your main problem was your lack of a form. When you try to submit inputs for posting you need to have a form. The form tells the page:
GETorPOSTaction=""tagThere are additional attributes that the form can provide but they aren’t relevant to your login form.
Finally, in order for a form to be posted to the respective page, a submit action has to be fired. Buttons can have a type of
buttonorsubmit. If you usetype="button"it is up to you to wire up an event to trigger when the button is clicked in theonclick=""attribute.For your purposes, you only need to submit your page and let the PHP do the rest. So for simplicity sake use
type="submit"as it performs a submit of the page without you having to wire up an appropriate function.Try these things first and let me know if you are still having issues. Happy Coding!
EDIT (ADDITIONAL ERRORS):
Another error I see is that your input fields do not have name attributes. When a form is posted the name attributes are sent through the respective stream (GET or POST). If no names are attached to the inputs, they will not be added to the stream.
It appears your PHP is expecting
$_POST['username']for the username input so add:to your username input field. It also appears that your PHP is expecting
$_POST['password']for the password field so add:to your password input. Also change the type on the password input from
texttopassword. If you want the most basic of security and want anyone to join your site at least hide their password while they type it.I recommend you start researching HTML and PHP by either purchasing a book on the topic(s) or by visiting a site such as W3Schools so you can learn and understand the basics of web design especially HTML as this is the base that you will be building on.