digitalimages
New Member
- Messages
- 47
- Reaction score
- 0
- Points
- 0
I have created a log in page and I have created a data base called "tiwebs_members" with a table called "members". I have added a test username and password to the table.
The login form code is:
The checklogin. php is below.
I have remove the actual password and username for myphpadmin for security.
When I try to login with the test user name and password I get an error message saying: "Wrong Username or Password " I assume that the code is working correctly but somehow not finding the data base. Using PHP 5.2
Any obvious problems? Suggestions? :dunno:
Thanks for any help.
The login form code is:
Code:
<form name='login' method='POST' action='checklogin.php' accept-charset='UTF-8'>
<input type='hidden' name='sfm_form_submitted' value='yes'>
<table cellspacing='0' cellpadding='5' border='0' bgcolor='#c1d0d7'>
<tr>
<td>
<table cellspacing='2' cellpadding='2' border='0'>
<tr>
<td colspan='2' align='center' class='form_heading'>
Client Login
</td>
</tr>
<tr>
<td align='right' class='normal_field'>
Username:
</td>
<td class='element_label'>
<input type='text' name='Name' size='30'>
</td>
</tr>
<tr>
<td align='right' class='normal_field'>
Password:
</td>
<td class='element_label'>
<input type='password' name='Password' size='30'>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<div id='login_Submit_errorloc' class='error_strings'>
</div>
<input type='submit' name='Submit' value='Login'>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
The checklogin. php is below.
Code:
<?php
ob_start();
$host="localhost"; // Host name
$username="removed_for _security"; // Mysql username
$password="removed_for _security"; // Mysql password
$db_name="tiwebs_members"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
I have remove the actual password and username for myphpadmin for security.
When I try to login with the test user name and password I get an error message saying: "Wrong Username or Password " I assume that the code is working correctly but somehow not finding the data base. Using PHP 5.2
Any obvious problems? Suggestions? :dunno:
Thanks for any help.
Last edited: