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

You may want to check the following:

1. Do you get any error message for database connectivity?
2. Do you already have the table 'users' and all fields ready?
3. Have you stored password is sha1 encrpted? You may need to sha1($pass) as a separate line before query to database

There is not error message for the database

I have all the tables and fields in the sql.

I think the problem is that my browser can't get through the lines:
$name = trim(addslashes($_POST["username"]));
$pass = trim(addslashes($_POST["password"]));

When i put the lines there, the page just goes blank

btw, how do u make sure that it is SHA ecripted?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.