Jump to content

whats wrong in my source

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
kiddies

kiddies

    Programmer

  • Members
  • PipPipPipPip
  • 130 posts
hello all...when i learning php to make login form in php, ive found a error, but i dont know what means, couse i following a tutorial, but i think that tutorial have a problem...

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


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Read http://forum.codecal...issues-php.html

#3
Overload

Overload

    Newbie

  • Members
  • PipPip
  • 16 posts
$count = mysql_num_rows($result);

is the line i assume?

#4
Guest_Jaan_*

Guest_Jaan_*
  • Guests
$sql="SELECT * FROM $tbl_name WHERE username ='$myusername' AND password='$mypassword'";

there was a cap between $tbl_ and name.. it should be $tbl_name not $tbl_ name