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
Change the part:
$a=@$_REQUEST['uname'];It is a temporary fix only.
$b=@$_REQUEST['pwd']; -
@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.