I need to make a login thing. I got some codes from another person, but it doesn't work for me. I double and tripled check to see if my apache server and mysql were set up correctly and they were. help?
sign-in:
<html>
<head>
<title>无标题文档</title>
</head>
<body>
<form action="checklogin.php" method="post">
<br>
<table border="0" cellpadding="2" cellspacing="2" width="42%">
<tbody><tr>
<td width="14%">Name</td><td width="86%">
<input style="background-color: rgb(255, 255, 160);" name="username" class="textbox" type="text"><br>
</td>
</tr>
<tr>
<td width="14%">Password</td>
<td width="86%">
<input name="password" class="textbox" type="password">
</td>
</tr>
<tr>
<td colspan="2">
<input name="Submit" value="Submit" type="submit">
</td>
</tr>
</tbody></table></form>
</body>
</html>
============================================
checklogin:
<?php
session_start();
$name = trim(addslashes($_POST["username"]));
$pass = trim(addslashes($_POST["password"]));
// you may also wish to perform extra security checks here, make sure the input is valid. adding slashes would be a good start
mysql_connect("localhost", "test_user", "password_123") or die("Couldn't Connect to Server " . mysql_error());
mysql_select_db("blog") or die("Database not found " . mysql_error());
$result = mysql_query("SELECT * FROM users WHERE username ='". $name . "' AND password='". sha1($pass) . "' ");
while ($row = mysql_fetch_array($result)){
if(mysql_num_rows($result) == 1){
print ("<h2>Login Details Verified, You May Click Below to Proceed</h2><BR>");
print ("<a href=\"blog.php\"Continue"</a>");
// You may want to assign a session variable here. This variable can then be checked on later pages that require the user to be logged in.
$_SESSION[ legal ] =1;
}
else {
Print "<h2>Invalid Username/Password</h2><BR>";
print "<a href=\"javascript:history.back(-1)\">Go Back, to try again.</a>";
}
}
?>
plz see watz wrong. thx