Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1133 | Replies: 3
![]() |
•
•
Join Date: Mar 2006
Posts: 14
Reputation:
Rep Power: 3
Solved Threads: 0
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]<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>[/html]
============================================
checklogin:
[php]<?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>";
}
}
?>[/php]
plz see watz wrong. thx
sign-in:
[html]<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>[/html]
============================================
checklogin:
[php]<?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>";
}
}
?>[/php]
plz see watz wrong. thx
Last edited by cscgal : May 3rd, 2006 at 11:36 am.
•
•
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation:
Rep Power: 4
Solved Threads: 6
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
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
Ecommerce-Web-Store.com Building Your e-Business.
•
•
Join Date: Mar 2006
Posts: 14
Reputation:
Rep Power: 3
Solved Threads: 0
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
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode