any 3 part to make php login
1.main.php
2.cek-login.php
3.login-sukses.php
1.main.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welocome to admin panel</title>
</head>
<body>
<table width="300" border"0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="cek-login.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><center><strong>ADMINISTRATOR LOGIN</strong></center></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername" /></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="submit" value="login" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>
2.cek-login.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cek Login</title>
</head>
<body>
<?php
$host="localhost";
$user="";
$pass="";
$db_name="";
$tbl_name="members";
$konek=mysql_connect("$host","$user","$pass") or die (mysql_error());
$pilih_db=mysql_select_db("$db_name") or die (mysql_error());
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
//login anti sqlinjection
$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);
$count=mysql_num_rows($result);
if ($count == 1) {
session_register('myusername');
session_register('mypassword');
header("location:login-sukses.php");
}
else
{
echo "Wrong, Username or Password";
}
?>
</body>
</html>
3.login-sukses.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
if(!session_is_registered(username)){
header("location:main-login.php");
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>login-sukses</title>
</head>
<body>
Login anda berhasil
</body>
</html>
when i run it...i ve an aerror like this
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\login\cek-login.php on line 32 Wrong, Username or Password
at cek-login.php..
help to correct that code, thanks
Edited by Jaan, 29 September 2009 - 08:22 AM.
Removed sensitive information


Sign In
Create Account


Back to top









