Replies
Welcome, guest
Join CrazyEngineers to reply, ask questions, and participate in conversations.
CrazyEngineers powered by Jatra Community Platform
-
@thebigk • Feb 27, 2013
#-Link-Snipped-# - Two things -
1. Is that the full error message? Is there any detail included after Undefined index:.. ?
2. Possible for you to post the code so that experts here can dig deeper? -
@whats-in-name-KdgM7o • Feb 28, 2013
The_Big_K#-Link-Snipped-# - Two things -
1. Is that the full error message? Is there any detail included after Undefined index:.. ?
2. Possible for you to post the code so that experts here can dig deeper?
Actually,here's the full message-
Notice: Undefined index: uname in C:\xampp\htdocs\project\login.php on line 5
Notice: Undefined index: pwd in C:\xampp\htdocs\project\login.php on line 6
and code-
<?php
session_start();
include("connection.php");
ob_start();
$a=$_REQUEST['uname'];
$b=$_REQUEST['pwd'];
if(isset($_REQUEST['sub_login']))
{
$query="select * from register where uname='$a' and pwd='$b'";
$queryexe=mysql_query($query);
$count=mysql_num_rows($queryexe);
$row=mysql_fetch_array($queryexe);
$id=$row['user_id'];
$_SESSION['user_id']=$id;
if($count>0)
{
header("location:profile.php");
}
else
{
?><script>alert("Invalid Username/Password");</script><?php
}
}
?>
<script>
function validation()
{
if(document.login.uname.value=="")
{
alert("Please Enter Your Username")
document.login.uname.focus();
return false;
}
if(document.login.pwd.value=="")
{
alert("Please Enter Your Password")
document.login.pwd.focus();
return false;
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login</title>
</head>
<body>
<form method="post" name="login" onSubmit="return validation();">
<table>
<tr>
<td>Username</td>
<td><input type="text" name= "uname" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name= "pwd" /></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" name="sub_login" style="background: url(images/open.gif) no-repeat; width:120px; height:50px; text-indent: -1000em;cursor:pointer;border:none;"/></td>
</tr>
</table>
</form>
</body>
</html> -
@thebigk • Feb 28, 2013
#-Link-Snipped-# , #-Link-Snipped-# - over to you, folks. 😀 -
@manish-r2Hoep • Feb 28, 2013
That's a bad coding art, you must check if there is any data in $_REQUEST or not assuming uname and pwd will always be present in data, if not then check isset($_REQUEST['uname'])
if(!empty($_REQUEST)){ } -
@praveenkumar-66Ze92 • Mar 1, 2013
-
@simplycoder-NsBEdD • Mar 1, 2013
I agree with goyal, never assume that the program would behave the way you think it will be.
When a developer develops something, he/she performs unit testing without much of destructive cases(a happy flow), but ideally this is a bad and a wrong practice to assume. Always check for values, same applies when session variables are being stored or retrieved. -
@whats-in-name-KdgM7o • Mar 1, 2013
@all,Thanks a lot for the replies,they were really informative,
#-Link-Snipped-#,it solved my problem,thank you.And I will keep it in mind to check for values.